Merge from mainline (r148296:149346)
[official-gcc/graphite-test-results.git] / gcc / testsuite / gcc.target / arm / fp16-rounding-alt-1.c
blobf50b4475f1902493decf9dc6f477392da27a72c6
1 /* Test intermediate rounding of double to float and then to __fp16, using
2 an example of a number that would round differently if it went directly
3 from double to __fp16. */
5 /* { dg-do run } */
6 /* { dg-options "-mfp16-format=alternative" } */
8 #include <stdlib.h>
10 /* The original double value. */
11 #define ORIG 0x1.0020008p0
13 /* The expected (double)((__fp16)((float)ORIG)) value. */
14 #define ROUNDED 0x1.0000000p0
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;