PR c++/67273
[official-gcc.git] / gcc / testsuite / gcc.target / arm / fp16-rounding-ieee-1.c
blob194dc9dc3bdff9721c5a37e0ec06b1a7d6627a4c
1 /* Test that rounding double to __fp16 happens directly, using an example
2 of a number that would round differently if it went from double to
3 __fp16 via float. */
5 /* { dg-do run } */
6 /* { dg-options "-mfp16-format=ieee" } */
8 #include <stdlib.h>
10 /* The original double value. */
11 #define ORIG 0x1.0020008p0
13 /* The expected (double)((__fp16)ORIG) value. */
14 #define ROUNDED 0x1.0040000p0
16 typedef union u {
17 __fp16 f;
18 unsigned short h;
19 } ufh;
21 ufh s = { ORIG };
22 ufh r = { ROUNDED };
24 double d = ORIG;
26 int
27 main (void)
29 ufh x;
31 /* Test that the rounding is correct for static initializers. */
32 if (s.h != r.h)
33 abort ();
35 /* Test that the rounding is correct for a casted constant expression
36 not in a static initializer. */
37 x.f = (__fp16)ORIG;
38 if (x.h != r.h)
39 abort ();
41 /* Test that the rounding is correct for a runtime conversion. */
42 x.f = (__fp16)d;
43 if (x.h != r.h)
44 abort ();
46 return 0;