PR c++/11645
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-20.c
bloba4e24a8029b3452691ad2273e153b48d7cbf44c8
1 /* Copyright (C) 2003 Free Software Foundation.
3 Verify that built-in math function constant folding doesn't break
4 anything and produces the expected results.
6 Written by Roger Sayle, 8th June 2003. */
8 /* { dg-do link } */
9 /* { dg-options "-O2 -ffast-math" } */
11 extern void link_error(void);
13 void test1(double x)
15 if (cos(x) != cos(-x))
16 link_error ();
18 if (sin(x)/cos(x) != tan(x))
19 link_error ();
21 if (cos(x)/sin(x) != 1.0/tan(x))
22 link_error ();
24 if (tan(x)*cos(x) != sin(x))
25 link_error ();
27 if (cos(x)*tan(x) != sin(x))
28 link_error ();
31 void test2(double x, double y)
33 if (-tan(x-y) != tan(y-x))
34 link_error ();
36 if (-sin(x-y) != sin(y-x))
37 link_error ();
40 void test1f(float x)
42 if (cosf(x) != cosf(-x))
43 link_error ();
45 if (sinf(x)/cosf(x) != tanf(x))
46 link_error ();
48 if (cosf(x)/sinf(x) != 1.0f/tanf(x))
49 link_error ();
51 if (tanf(x)*cosf(x) != sinf(x))
52 link_error ();
54 if (cosf(x)*tanf(x) != sinf(x))
55 link_error ();
58 void test2f(float x, float y)
60 if (-tanf(x-y) != tanf(y-x))
61 link_error ();
63 if (-sinf(x-y) != sinf(y-x))
64 link_error ();
68 void test1l(long double x)
70 if (cosl(x) != cosl(-x))
71 link_error ();
73 if (sinl(x)/cosl(x) != tanl(x))
74 link_error ();
76 if (cosl(x)/sinl(x) != 1.0l/tanl(x))
77 link_error ();
79 if (tanl(x)*cosl(x) != sinl(x))
80 link_error ();
82 if (cosl(x)*tanl(x) != sinl(x))
83 link_error ();
86 void test2l(long double x, long double y)
88 if (-tanl(x-y) != tanl(y-x))
89 link_error ();
91 if (-sinl(x-y) != sinl(y-x))
92 link_error ();
95 int main()
97 test1 (1.0);
98 test2 (1.0, 2.0);
100 test1f (1.0f);
101 test2f (1.0f, 2.0f);
103 test1l (1.0l);
104 test2l (1.0l, 2.0l);
106 return 0;