1 /* { dg-do run } */
2 /* { dg-require-effective-target dfprt } */
3 /* { dg-options "-O2" } */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 /* Runnable test case for testing _Decimal128 to _Decimal32 rounding.
9 The value below when rounded to _Decimal64 would result in the value
10 1.2345675e+00, which if it were rounded to _Decimal32 would result in
11 the value 1.234568e+00. However, the correct value when rounding from
12 _Decimal128 directly to _Decimal32 is 1.234567e+00. */
13
14 _Decimal128 td = 1.23456749999999999999e+00dl;
15 _Decimal32 sd_expected = 1.234567e+00df;
16
17 _Decimal32 __attribute__((noinline))
18 td2sd (_Decimal128 td)
19 {
20 return td;
21 }
22
23 int
24 main (void)
25 {
26 _Decimal32 sd = td2sd (td);
27 if (sd != sd_expected)
28 {
29 union {
30 _Decimal32 sd;
31 unsigned int i;
32 } u;
33
34 printf ("cast to _Decimal32 failed:\n");
35 u.sd = sd;
36 printf (" actual = 0x%x\n", u.i);
37 u.sd = sd_expected;
38 printf (" expected = 0x%x\n", u.i);
39 abort ();
40 }
41
42 return 0;
43 }