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.  */
4 
5 /* { dg-do run } */
6 /* { dg-options "-mfp16-format=ieee" } */
7 
8 #include <stdlib.h>
9 
10 /* The original double value.  */
11 #define ORIG 0x1.0020008p0
12 
13 /* The expected (double)((__fp16)ORIG) value.  */
14 #define ROUNDED 0x1.0040000p0
15 
16 typedef union u {
17   __fp16 f;
18   unsigned short h;
19 } ufh;
20 
21 ufh s = { ORIG };
22 ufh r = { ROUNDED };
23 
24 double d = ORIG;
25 
26 int
main(void)27 main (void)
28 {
29   ufh x;
30 
31   /* Test that the rounding is correct for static initializers.  */
32   if (s.h != r.h)
33     abort ();
34 
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 ();
40 
41   /* Test that the rounding is correct for a runtime conversion.  */
42   x.f = (__fp16)d;
43   if (x.h != r.h)
44     abort ();
45 
46   return 0;
47 }
48