1 /* Copyright (C) 2003,2007 Free Software Foundation.
2 
3    Check that constant folding of built-in math functions doesn't
4    break anything and produces the expected results.
5 
6    Written by Roger Sayle, 5th April 2003.  */
7 
8 /* { dg-do link } */
9 /* { dg-options "-O2 -ffast-math" } */
10 
11 extern void link_error(void);
12 
13 extern double exp(double);
14 extern double sqrt(double);
15 extern double cbrt(double);
16 extern double pow(double,double);
17 
test(double x,double y,double z)18 void test(double x, double y, double z)
19 {
20   if (sqrt(x)*sqrt(x) != x)
21     link_error ();
22 
23   if (sqrt(x)*sqrt(y) != sqrt(x*y))
24     link_error ();
25 
26   if (exp(x)*exp(y) != exp(x+y))
27     link_error ();
28 
29   if (pow(x,y)*pow(z,y) != pow(z*x,y))
30     link_error ();
31 
32   if (pow(x,y)*pow(x,z) != pow(x,y+z))
33     link_error ();
34 
35   if (x/exp(y) != x*exp(-y))
36     link_error ();
37 
38   if (x/pow(y,z) != x*pow(y,-z))
39     link_error ();
40 
41   if (x/sqrt(y/z) != x*sqrt(z/y))
42     link_error ();
43 
44   if (x/cbrt(y/z) != x*cbrt(z/y))
45     link_error ();
46 }
47 
main()48 int main()
49 {
50   test (2.0, 3.0, 4.0);
51   return 0;
52 }
53 
54