aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/pr92488.c
blob: 3ca575531ca398bdbdb5d62c3fd43d571fc3365d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* { dg-do run } */
/* { dg-require-effective-target dfprt } */
/* { dg-options "-O2" } */

#include <stdio.h>
#include <stdlib.h>

/* Runnable test case for testing _Decimal128 to _Decimal32 rounding.
   The value below when rounded to _Decimal64 would result in the value
   1.2345675e+00, which if it were rounded to _Decimal32 would result in
   the value 1.234568e+00.  However, the correct value when rounding from
   _Decimal128  directly to _Decimal32 is 1.234567e+00.  */

_Decimal128 td = 1.23456749999999999999e+00dl;
_Decimal32 sd_expected = 1.234567e+00df;

_Decimal32 __attribute__((noinline))
td2sd (_Decimal128 td)
{
  return td;
}

int
main (void)
{
  _Decimal32 sd = td2sd (td);
  if (sd != sd_expected)
    {
      union {
	_Decimal32 sd;
	unsigned int i;
      } u;

      printf ("cast to _Decimal32 failed:\n");
      u.sd = sd;
      printf ("  actual   = 0x%x\n", u.i);
      u.sd = sd_expected;
      printf ("  expected = 0x%x\n", u.i);
      abort ();
    }

  return 0;
}