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