Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-10.c
blob53158a0f8523071a21ebcfab8182d3d517abe4c5
1 /* Copyright (C) 2003 Free Software Foundation.
3 Check that constant folding of built-in math functions doesn't
4 break anything and produces the expected results.
6 Written by Roger Sayle, 2nd April 2003. */
8 /* { dg-do link } */
9 /* { dg-options "-O2 -ffast-math" } */
11 extern void link_error(void);
13 extern double exp(double);
14 extern double log(double);
15 extern double sqrt(double);
16 extern double pow(double,double);
17 extern double fabs(double);
19 void test(double x)
21 /*if (sqrt(pow(x,4.0)) != x*x)
22 link_error (); */
24 if (pow(sqrt(x),4.0) != x*x)
25 link_error ();
27 if (pow(pow(x,4.0),0.25) != x)
28 link_error ();
31 void test2(double x, double y, double z)
33 if (sqrt(pow(x,y)) != pow(fabs(x),y*0.5))
34 link_error ();
36 if (log(pow(x,y)) != y*log(x))
37 link_error ();
39 if (pow(exp(x),y) != exp(x*y))
40 link_error ();
42 if (pow(sqrt(x),y) != pow(x,y*0.5))
43 link_error ();
45 if (pow(pow(x,y),z) != pow(x,y*z))
46 link_error ();
49 int main()
51 test (2.0);
52 test2 (2.0, 3.0, 4.0);
53 return 0;