]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/decimal/make-decimal.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / decimal / make-decimal.cc
CommitLineData
a5544970 1// Copyright (C) 2009-2019 Free Software Foundation, Inc.
4cdc8761
BK
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.
8
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.
13
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/>.
17
02ebbe2f 18// { dg-require-effective-target dfp }
4ed6e524 19// { dg-options "-Wno-pedantic" }
4cdc8761
BK
20
21// ISO/IEC TR 24733 3.2.5 Initialization from coefficient and exponent.
22
23#include <decimal/decimal>
24#include <cstring>
25#include <testsuite_hooks.h>
26
27#define PASTE2(A,B) A ## B
28#define PASTE(A,B) PASTE2(A,B)
29
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); \
33 i = ESIGN EXP; \
34 a = PASTE(make_decimal,32) (sll, i); \
35 b = PASTE(make_decimal,32) (PASTE(COEFF,LL), ESIGN EXP); \
ef859c9d
PC
36 VERIFY ((std::memcmp ((void *)&x, (void *)&a, SIZE) == 0) \
37 && (std::memcmp ((void *)&x, (void *)&b,SIZE) == 0));
4cdc8761
BK
38
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); \
43 i = ESIGN EXP; \
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); \
ef859c9d
PC
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));
4cdc8761
BK
52
53using namespace std::decimal;
54
55void
56make_decimal_32 (void)
57{
58 decimal32 a, b, c, d;
59 float x __attribute__((mode(SD)));
60 int i;
61 unsigned long sz = sizeof (decimal32);
62 volatile long long sll;
63 volatile unsigned long long ull;
64
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);
77}
78
79void
80make_decimal_64 (void)
81{
82 decimal64 a, b, c, d;
83 float x __attribute__((mode(DD)));
84 int i;
85 unsigned long sz = sizeof (decimal64);
86 volatile long long sll;
87 volatile unsigned long long ull;
88
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);
101}
102
103void
104make_decimal_128 (void)
105{
106 decimal128 a, b, c, d;
107 float x __attribute__((mode(TD)));
108 int i;
109 unsigned long sz = sizeof (decimal128);
110 volatile long long sll;
111 volatile unsigned long long ull;
112
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);
125}
126
127int
128main ()
129{
130 make_decimal_32 ();
131 make_decimal_64 ();
132 make_decimal_128 ();
133}