OSDN Git Service

* gcc.dg/altivec-vec-merge.c: Make test usable on GNU/Linux targets
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / builtins-20.c
1 /* Copyright (C) 2003  Free Software Foundation.
2
3    Verify that built-in math function constant folding doesn't break
4    anything and produces the expected results.
5
6    Written by Roger Sayle, 8th June 2003.  */
7
8 /* { dg-do link } */
9 /* { dg-options "-O2 -ffast-math" } */
10
11 #include "builtins-config.h"
12
13 extern double cos (double);
14 extern double sin (double);
15 extern double tan (double);
16 extern float cosf (float);
17 extern float sinf (float);
18 extern float tanf (float);
19 extern long double cosl (long double);
20 extern long double sinl (long double);
21 extern long double tanl (long double);
22
23 extern void link_error(void);
24
25 void test1(double x)
26 {
27   if (cos(x) != cos(-x))
28     link_error ();
29
30   if (sin(x)/cos(x) != tan(x))
31     link_error ();
32
33   if (cos(x)/sin(x) != 1.0/tan(x))
34     link_error ();
35
36   if (tan(x)*cos(x) != sin(x))
37     link_error ();
38
39   if (cos(x)*tan(x) != sin(x))
40     link_error ();
41 }
42
43 void test2(double x, double y)
44 {
45   if (-tan(x-y) != tan(y-x))
46     link_error ();
47
48   if (-sin(x-y) != sin(y-x))
49     link_error ();
50 }
51
52 void test1f(float x)
53 {
54   if (cosf(x) != cosf(-x))
55     link_error ();
56
57 #ifdef HAVE_C99_RUNTIME
58   if (sinf(x)/cosf(x) != tanf(x))
59     link_error ();
60
61   if (cosf(x)/sinf(x) != 1.0f/tanf(x))
62     link_error ();
63
64   if (tanf(x)*cosf(x) != sinf(x))
65     link_error ();
66
67   if (cosf(x)*tanf(x) != sinf(x))
68     link_error ();
69 #endif
70 }
71
72 void test2f(float x, float y)
73 {
74   if (-tanf(x-y) != tanf(y-x))
75     link_error ();
76
77   if (-sinf(x-y) != sinf(y-x))
78     link_error ();
79 }
80
81
82 void test1l(long double x)
83 {
84   if (cosl(x) != cosl(-x))
85     link_error ();
86
87 #ifdef HAVE_C99_RUNTIME
88   if (sinl(x)/cosl(x) != tanl(x))
89     link_error ();
90
91   if (cosl(x)/sinl(x) != 1.0l/tanl(x))
92     link_error ();
93
94   if (tanl(x)*cosl(x) != sinl(x))
95     link_error ();
96
97   if (cosl(x)*tanl(x) != sinl(x))
98     link_error ();
99 #endif
100 }
101
102 void test2l(long double x, long double y)
103 {
104   if (-tanl(x-y) != tanl(y-x))
105     link_error ();
106
107   if (-sinl(x-y) != sinl(y-x))
108     link_error ();
109 }
110
111 int main()
112 {
113   test1 (1.0);
114   test2 (1.0, 2.0);
115
116   test1f (1.0f);
117   test2f (1.0f, 2.0f);
118
119   test1l (1.0l);
120   test2l (1.0l, 2.0l);
121
122   return 0;
123 }
124