* lib/target-supports.exp (check_effective_target_hard_dfp): New.
[official-gcc.git] / gcc / testsuite / gcc.dg / dfp / convert-dfp-round.c
blob9833abb7ff0bf5613ecda948cf34d71907534e25
1 /* { dg-options "-O0 -std=gnu99" } */
2 /* { dg-skip-if "test is for emulation" { hard_dfp } { "*" } { "" } } */
4 /* N1150 5.2: Conversions among decimal floating types and between
5 decimal floating types and generic floating types.
6 C99 6.3.1.5(3) New.
8 Perform conversions between DFP types in which the assigned value
9 cannot be represented exactly in the result and must be rounded
10 correctly according to the current rounding mode.
12 Normally this would not be part of compiler testing, but conversions
13 are currently handled in libgcc via decNumber. */
15 #include "dfp-round.h"
17 extern void abort (void);
18 static int failcnt = 0;
20 /* Support compiling the test to report individual failures; default is
21 to abort as soon as a check fails. */
22 #ifdef DBG
23 #include <stdio.h>
24 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
25 #else
26 #define FAILURE abort ();
27 #endif
29 _Decimal32 d32;
30 _Decimal64 d64;
31 _Decimal128 d128;
33 _Decimal32 d64_to_d32 (_Decimal64 d) { return d; }
34 _Decimal64 d128_to_d64 (_Decimal128 d) { return d; }
35 _Decimal32 d128_to_d32 (_Decimal128 d) { return d; }
37 int
38 do_d64_to_d32 (_Decimal64 orig, _Decimal32 exp)
40 d64 = orig;
41 d32 = d64_to_d32 (d64);
42 return (d32 == exp);
45 int
46 do_d128_to_d32 (_Decimal128 orig, _Decimal32 exp)
48 d128 = orig;
49 d32 = d128_to_d32 (d128);
50 return (d32 == exp);
53 int
54 do_d128_to_d64 (_Decimal128 orig, _Decimal64 exp)
56 d128 = orig;
57 d64 = d128_to_d64 (d128);
58 return (d64 == exp);
61 int
62 main ()
64 DFP_SETROUND (FE_DEC_DOWNWARD);
65 if (!do_d64_to_d32 (1.1111125dd, 1.111112df)) FAILURE
66 if (!do_d64_to_d32 (1.1111135dd, 1.111113df)) FAILURE
67 if (!do_d64_to_d32 (-1.1111125dd, -1.111113df)) FAILURE
68 if (!do_d64_to_d32 (-1.1111135dd, -1.111114df)) FAILURE
69 if (!do_d128_to_d32 (1.1111125dl, 1.111112df)) FAILURE
70 if (!do_d128_to_d32 (1.1111135dl, 1.111113df)) FAILURE
71 if (!do_d128_to_d32 (-1.1111125dl, -1.111113df)) FAILURE
72 if (!do_d128_to_d32 (-1.1111135dl, -1.111114df)) FAILURE
73 if (!do_d128_to_d64 (1.1111111111111125dl, 1.111111111111112dd)) FAILURE
74 if (!do_d128_to_d64 (1.1111111111111135dl, 1.111111111111113dd)) FAILURE
75 if (!do_d128_to_d64 (-1.1111111111111125dl, -1.111111111111113dd)) FAILURE
76 if (!do_d128_to_d64 (-1.1111111111111135dl, -1.111111111111114dd)) FAILURE
78 DFP_SETROUND (FE_DEC_TONEAREST);
79 if (!do_d64_to_d32 (1.1111125dd, 1.111112df)) FAILURE
80 if (!do_d64_to_d32 (1.1111135dd, 1.111114df)) FAILURE
81 if (!do_d64_to_d32 (-1.1111125dd, -1.111112df)) FAILURE
82 if (!do_d64_to_d32 (-1.1111135dd, -1.111114df)) FAILURE
83 if (!do_d128_to_d32 (1.1111125dl, 1.111112df)) FAILURE
84 if (!do_d128_to_d32 (1.1111135dl, 1.111114df)) FAILURE
85 if (!do_d128_to_d32 (-1.1111125dl, -1.111112df)) FAILURE
86 if (!do_d128_to_d32 (-1.1111135dl, -1.111114df)) FAILURE
87 if (!do_d128_to_d64 (1.1111111111111125dl, 1.111111111111112dd)) FAILURE
88 if (!do_d128_to_d64 (1.1111111111111135dl, 1.111111111111114dd)) FAILURE
89 if (!do_d128_to_d64 (-1.1111111111111125dl, -1.111111111111112dd)) FAILURE
90 if (!do_d128_to_d64 (-1.1111111111111135dl, -1.111111111111114dd)) FAILURE
92 DFP_SETROUND (FE_DEC_TONEARESTFROMZERO);
93 if (!do_d64_to_d32 (1.1111125dd, 1.111113df)) FAILURE
94 if (!do_d64_to_d32 (1.1111135dd, 1.111114df)) FAILURE
95 if (!do_d64_to_d32 (-1.1111125dd, -1.111113df)) FAILURE
96 if (!do_d64_to_d32 (-1.1111135dd, -1.111114df)) FAILURE
97 if (!do_d128_to_d32 (1.1111125dl, 1.111113df)) FAILURE
98 if (!do_d128_to_d32 (1.1111135dl, 1.111114df)) FAILURE
99 if (!do_d128_to_d32 (-1.1111125dl, -1.111113df)) FAILURE
100 if (!do_d128_to_d32 (-1.1111135dl, -1.111114df)) FAILURE
101 if (!do_d128_to_d64 (1.1111111111111125dl, 1.111111111111113dd)) FAILURE
102 if (!do_d128_to_d64 (1.1111111111111135dl, 1.111111111111114dd)) FAILURE
103 if (!do_d128_to_d64 (-1.1111111111111125dl, -1.111111111111113dd)) FAILURE
104 if (!do_d128_to_d64 (-1.1111111111111135dl, -1.111111111111114dd)) FAILURE
106 DFP_SETROUND (FE_DEC_TOWARDZERO);
107 if (!do_d64_to_d32 (1.1111125dd, 1.111112df)) FAILURE
108 if (!do_d64_to_d32 (1.1111135dd, 1.111113df)) FAILURE
109 if (!do_d64_to_d32 (-1.1111125dd, -1.111112df)) FAILURE
110 if (!do_d64_to_d32 (-1.1111135dd, -1.111113df)) FAILURE
111 if (!do_d128_to_d32 (1.1111125dl, 1.111112df)) FAILURE
112 if (!do_d128_to_d32 (1.1111135dl, 1.111113df)) FAILURE
113 if (!do_d128_to_d32 (-1.1111125dl, -1.111112df)) FAILURE
114 if (!do_d128_to_d32 (-1.1111135dl, -1.111113df)) FAILURE
115 if (!do_d128_to_d64 (1.1111111111111125dl, 1.111111111111112dd)) FAILURE
116 if (!do_d128_to_d64 (1.1111111111111135dl, 1.111111111111113dd)) FAILURE
117 if (!do_d128_to_d64 (-1.1111111111111125dl, -1.111111111111112dd)) FAILURE
118 if (!do_d128_to_d64 (-1.1111111111111135dl, -1.111111111111113dd)) FAILURE
120 DFP_SETROUND (FE_DEC_UPWARD);
121 if (!do_d64_to_d32 (1.1111125dd, 1.111113df)) FAILURE
122 if (!do_d64_to_d32 (1.1111135dd, 1.111114df)) FAILURE
123 if (!do_d64_to_d32 (-1.1111125dd, -1.111112df)) FAILURE
124 if (!do_d64_to_d32 (-1.1111135dd, -1.111113df)) FAILURE
125 if (!do_d128_to_d32 (1.1111125dl, 1.111113df)) FAILURE
126 if (!do_d128_to_d32 (1.1111135dl, 1.111114df)) FAILURE
127 if (!do_d128_to_d32 (-1.1111125dl, -1.111112df)) FAILURE
128 if (!do_d128_to_d32 (-1.1111135dl, -1.111113df)) FAILURE
129 if (!do_d128_to_d64 (1.1111111111111125dl, 1.111111111111113dd)) FAILURE
130 if (!do_d128_to_d64 (1.1111111111111135dl, 1.111111111111114dd)) FAILURE
131 if (!do_d128_to_d64 (-1.1111111111111125dl, -1.111111111111112dd)) FAILURE
132 if (!do_d128_to_d64 (-1.1111111111111135dl, -1.111111111111113dd)) FAILURE
134 if (failcnt)
135 abort ();
136 return 0;