2010-07-27 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / libstdc++-v3 / testsuite / decimal / make-decimal.cc
blobbe4fa4632addd5e68ea9b9d7e366f5ef5454943a
1 // Copyright (C) 2009 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-require-effective-target dfp }
20 // ISO/IEC TR 24733 3.2.5 Initialization from coefficient and exponent.
22 #include <decimal/decimal>
23 #include <cstring>
24 #include <testsuite_hooks.h>
26 #define PASTE2(A,B) A ## B
27 #define PASTE(A,B) PASTE2(A,B)
29 #define TESTVAL_NEG(COEFF,ESIGN,EXP,SUF,NUM,SIZE) \
30 x = PASTE(PASTE(PASTE(PASTE(PASTE(COEFF,.),E),ESIGN),EXP),SUF); \
31 sll = PASTE(COEFF,LL); \
32 i = ESIGN EXP; \
33 a = PASTE(make_decimal,32) (sll, i); \
34 b = PASTE(make_decimal,32) (PASTE(COEFF,LL), ESIGN EXP); \
35 VERIFY ((__builtin_memcmp ((void *)&x, (void *)&a, SIZE) == 0) \
36 && (__builtin_memcmp ((void *)&x, (void *)&b,SIZE) == 0));
38 #define TESTVAL_NONNEG(COEFF,ESIGN,EXP,SUF,NUM,SIZE) \
39 x = PASTE(PASTE(PASTE(PASTE(PASTE(COEFF,.),E),ESIGN),EXP),SUF); \
40 sll = PASTE(COEFF,LL); \
41 ull = PASTE(COEFF,ULL); \
42 i = ESIGN EXP; \
43 a = PASTE(make_decimal,32) (sll, i); \
44 b = PASTE(make_decimal,32) (PASTE(COEFF,LL), ESIGN EXP); \
45 c = PASTE(make_decimal,32) (ull, i); \
46 d = PASTE(make_decimal,32) (PASTE(COEFF,ULL), ESIGN EXP); \
47 VERIFY ((__builtin_memcmp ((void *)&x, (void *)&a, SIZE) == 0) \
48 && (__builtin_memcmp ((void *)&x, (void *)&b,SIZE) == 0) \
49 && (__builtin_memcmp ((void *)&x, (void *)&c,SIZE) == 0) \
50 && (__builtin_memcmp ((void *)&x, (void *)&d,SIZE) == 0));
52 using namespace std::decimal;
54 void
55 make_decimal_32 (void)
57 decimal32 a, b, c, d;
58 float x __attribute__((mode(SD)));
59 int i;
60 unsigned long sz = sizeof (decimal32);
61 volatile long long sll;
62 volatile unsigned long long ull;
64 TESTVAL_NONNEG (0, +, 0, DF, 32, sz);
65 TESTVAL_NONNEG (5, +, 1, DF, 32, sz);
66 TESTVAL_NONNEG (50, +, 0, DF, 32, sz);
67 TESTVAL_NONNEG (500, +, 0, DF, 32, sz);
68 TESTVAL_NEG (-25, -, 3, DF, 32, sz)
69 TESTVAL_NEG (-500, +, 0, DF, 32, sz);
70 TESTVAL_NONNEG (999999, +, 91, DF, 32, sz);
71 TESTVAL_NONNEG (1, -, 9, DF, 32, sz);
72 TESTVAL_NONNEG (1, -, 90, DF, 32, sz);
73 TESTVAL_NONNEG (1, -, 95, DF, 32, sz);
74 TESTVAL_NONNEG (1, -, 101, DF, 32, sz);
75 TESTVAL_NEG (-1, -, 101, DF, 32, sz);
78 void
79 make_decimal_64 (void)
81 decimal64 a, b, c, d;
82 float x __attribute__((mode(DD)));
83 int i;
84 unsigned long sz = sizeof (decimal64);
85 volatile long long sll;
86 volatile unsigned long long ull;
88 TESTVAL_NONNEG (0, +, 0, DF, 64, sz);
89 TESTVAL_NONNEG (5, +, 1, DF, 64, sz);
90 TESTVAL_NONNEG (50, +, 0, DF, 64, sz);
91 TESTVAL_NONNEG (500, +, 0, DF, 64, sz);
92 TESTVAL_NEG (-25, -, 3, DF, 64, sz)
93 TESTVAL_NEG (-500, +, 0, DF, 64, sz);
94 TESTVAL_NONNEG (999999, +, 91, DF, 64, sz);
95 TESTVAL_NONNEG (1, -, 9, DF, 64, sz);
96 TESTVAL_NONNEG (1, -, 90, DF, 64, sz);
97 TESTVAL_NONNEG (1, -, 95, DF, 64, sz);
98 TESTVAL_NONNEG (1, -, 101, DF, 64, sz);
99 TESTVAL_NEG (-1, -, 101, DF, 64, sz);
102 void
103 make_decimal_128 (void)
105 decimal128 a, b, c, d;
106 float x __attribute__((mode(TD)));
107 int i;
108 unsigned long sz = sizeof (decimal128);
109 volatile long long sll;
110 volatile unsigned long long ull;
112 TESTVAL_NONNEG (0, +, 0, DF, 128, sz);
113 TESTVAL_NONNEG (5, +, 1, DF, 128, sz);
114 TESTVAL_NONNEG (50, +, 0, DF, 128, sz);
115 TESTVAL_NONNEG (500, +, 0, DF, 128, sz);
116 TESTVAL_NEG (-25, -, 3, DF, 128, sz)
117 TESTVAL_NEG (-500, +, 0, DF, 128, sz);
118 TESTVAL_NONNEG (999999, +, 91, DF, 128, sz);
119 TESTVAL_NONNEG (1, -, 9, DF, 128, sz);
120 TESTVAL_NONNEG (1, -, 90, DF, 128, sz);
121 TESTVAL_NONNEG (1, -, 95, DF, 128, sz);
122 TESTVAL_NONNEG (1, -, 101, DF, 128, sz);
123 TESTVAL_NEG (-1, -, 101, DF, 128, sz);
127 main ()
129 make_decimal_32 ();
130 make_decimal_64 ();
131 make_decimal_128 ();