OSDN Git Service

2009-06-18 Sandra Loosemore <sandra@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / arm / fp16-rounding-ieee-1.c
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.  */
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)((float)ORIG)) value.  */
14 #define ROUNDED 0x1.0000000p0
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
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 }