OSDN Git Service

* gcc.dg/builtins-29.c: New test case.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / builtins-29.c
1 /* Copyright (C) 2004 Free Software Foundation.
2
3    Check that constant folding of round, roundf and roundl math functions
4    doesn't break anything and produces the expected results.
5
6    Written by Roger Sayle, 22nd January 2004.  */
7
8 /* { dg-do link } */
9 /* { dg-options "-O2" } */
10
11 extern void link_error(void);
12
13 extern double round(double);
14 extern float roundf(float);
15 extern long double roundl(long double);
16
17 void test()
18 {
19   if (round (0.0) != 0.0)
20     link_error ();
21   if (round (6.0) != 6.0)
22     link_error ();
23   if (round (-8.0) != -8.0)
24     link_error ();
25
26   if (round (3.2) != 3.0)
27     link_error ();
28   if (round (-2.8) != -3.0)
29     link_error ();
30   if (round (0.01) != 0.0)
31     link_error ();
32   if (round (-0.7) != -1.0)
33     link_error ();
34
35   if (round (2.5) != 3.0)
36     link_error ();
37   if (round (-1.5) != -2.0)
38     link_error ();
39 }
40
41 void testf()
42 {
43   if (roundf (0.0f) != 0.0f)
44     link_error ();
45   if (roundf (6.0f) != 6.0f)
46     link_error ();
47   if (roundf (-8.0f) != -8.0f)
48     link_error ();
49
50   if (roundf (3.2f) != 3.0f)
51     link_error ();
52   if (roundf (-2.8f) != -3.0f)
53     link_error ();
54   if (roundf (0.01f) != 0.0f)
55     link_error ();
56   if (roundf (-0.7f) != -1.0f)
57     link_error ();
58
59   if (roundf (2.5f) != 3.0f)
60     link_error ();
61   if (roundf (-1.5f) != -2.0f)
62     link_error ();
63 }
64
65 void testl()
66 {
67   if (roundl (0.0l) != 0.0l)
68     link_error ();
69   if (roundl (6.0l) != 6.0l)
70     link_error ();
71   if (roundl (-8.0l) != -8.0l)
72     link_error ();
73
74   if (roundl (3.2l) != 3.0l)
75     link_error ();
76   if (roundl (-2.8l) != -3.0l)
77     link_error ();
78   if (roundl (0.01l) != 0.0l)
79     link_error ();
80   if (roundl (-0.7l) != -1.0l)
81     link_error ();
82
83   if (roundl (2.5l) != 3.0l)
84     link_error ();
85   if (roundl (-1.5l) != -2.0l)
86     link_error ();
87 }
88
89 int main()
90 {
91   test ();
92   testf ();
93   testl ();
94   return 0;
95 }
96