1 // Copyright (C) 2009-2018 Free Software Foundation, Inc.
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)
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 }
19 // { dg-options "-Wno-pedantic" }
21 // ISO/IEC TR 24733 3.2.5 Initialization from coefficient and exponent.
23 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
27 #define PASTE2(A,B) A ## B
28 #define PASTE(A,B) PASTE2(A,B)
30 #define TESTVAL_NEG(COEFF,ESIGN,EXP,SUF,NUM,SIZE) \
31 x = PASTE(PASTE(PASTE(PASTE(PASTE(COEFF,.),E),ESIGN),EXP),SUF); \
32 sll = PASTE(COEFF,LL); \
34 a = PASTE(make_decimal,32) (sll, i); \
35 b = PASTE(make_decimal,32) (PASTE(COEFF,LL), ESIGN EXP); \
36 VERIFY ((std::memcmp ((void *)&x, (void *)&a, SIZE) == 0) \
37 && (std::memcmp ((void *)&x, (void *)&b,SIZE) == 0));
39 #define TESTVAL_NONNEG(COEFF,ESIGN,EXP,SUF,NUM,SIZE) \
40 x = PASTE(PASTE(PASTE(PASTE(PASTE(COEFF,.),E),ESIGN),EXP),SUF); \
41 sll = PASTE(COEFF,LL); \
42 ull = PASTE(COEFF,ULL); \
44 a = PASTE(make_decimal,32) (sll, i); \
45 b = PASTE(make_decimal,32) (PASTE(COEFF,LL), ESIGN EXP); \
46 c = PASTE(make_decimal,32) (ull, i); \
47 d = PASTE(make_decimal,32) (PASTE(COEFF,ULL), ESIGN EXP); \
48 VERIFY ((std::memcmp ((void *)&x, (void *)&a, SIZE) == 0) \
49 && (std::memcmp ((void *)&x, (void *)&b,SIZE) == 0) \
50 && (std::memcmp ((void *)&x, (void *)&c,SIZE) == 0) \
51 && (std::memcmp ((void *)&x, (void *)&d,SIZE) == 0));
53 using namespace std::decimal
;
56 make_decimal_32 (void)
59 float x
__attribute__((mode(SD
)));
61 unsigned long sz
= sizeof (decimal32
);
62 volatile long long sll
;
63 volatile unsigned long long ull
;
65 TESTVAL_NONNEG (0, +, 0, DF
, 32, sz
);
66 TESTVAL_NONNEG (5, +, 1, DF
, 32, sz
);
67 TESTVAL_NONNEG (50, +, 0, DF
, 32, sz
);
68 TESTVAL_NONNEG (500, +, 0, DF
, 32, sz
);
69 TESTVAL_NEG (-25, -, 3, DF
, 32, sz
)
70 TESTVAL_NEG (-500, +, 0, DF
, 32, sz
);
71 TESTVAL_NONNEG (999999, +, 91, DF
, 32, sz
);
72 TESTVAL_NONNEG (1, -, 9, DF
, 32, sz
);
73 TESTVAL_NONNEG (1, -, 90, DF
, 32, sz
);
74 TESTVAL_NONNEG (1, -, 95, DF
, 32, sz
);
75 TESTVAL_NONNEG (1, -, 101, DF
, 32, sz
);
76 TESTVAL_NEG (-1, -, 101, DF
, 32, sz
);
80 make_decimal_64 (void)
83 float x
__attribute__((mode(DD
)));
85 unsigned long sz
= sizeof (decimal64
);
86 volatile long long sll
;
87 volatile unsigned long long ull
;
89 TESTVAL_NONNEG (0, +, 0, DF
, 64, sz
);
90 TESTVAL_NONNEG (5, +, 1, DF
, 64, sz
);
91 TESTVAL_NONNEG (50, +, 0, DF
, 64, sz
);
92 TESTVAL_NONNEG (500, +, 0, DF
, 64, sz
);
93 TESTVAL_NEG (-25, -, 3, DF
, 64, sz
)
94 TESTVAL_NEG (-500, +, 0, DF
, 64, sz
);
95 TESTVAL_NONNEG (999999, +, 91, DF
, 64, sz
);
96 TESTVAL_NONNEG (1, -, 9, DF
, 64, sz
);
97 TESTVAL_NONNEG (1, -, 90, DF
, 64, sz
);
98 TESTVAL_NONNEG (1, -, 95, DF
, 64, sz
);
99 TESTVAL_NONNEG (1, -, 101, DF
, 64, sz
);
100 TESTVAL_NEG (-1, -, 101, DF
, 64, sz
);
104 make_decimal_128 (void)
106 decimal128 a
, b
, c
, d
;
107 float x
__attribute__((mode(TD
)));
109 unsigned long sz
= sizeof (decimal128
);
110 volatile long long sll
;
111 volatile unsigned long long ull
;
113 TESTVAL_NONNEG (0, +, 0, DF
, 128, sz
);
114 TESTVAL_NONNEG (5, +, 1, DF
, 128, sz
);
115 TESTVAL_NONNEG (50, +, 0, DF
, 128, sz
);
116 TESTVAL_NONNEG (500, +, 0, DF
, 128, sz
);
117 TESTVAL_NEG (-25, -, 3, DF
, 128, sz
)
118 TESTVAL_NEG (-500, +, 0, DF
, 128, sz
);
119 TESTVAL_NONNEG (999999, +, 91, DF
, 128, sz
);
120 TESTVAL_NONNEG (1, -, 9, DF
, 128, sz
);
121 TESTVAL_NONNEG (1, -, 90, DF
, 128, sz
);
122 TESTVAL_NONNEG (1, -, 95, DF
, 128, sz
);
123 TESTVAL_NONNEG (1, -, 101, DF
, 128, sz
);
124 TESTVAL_NEG (-1, -, 101, DF
, 128, sz
);