OSDN Git Service

* builtins.c (fold_builtin): Constant fold expressions as x*0.5
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / builtins-10.c
1 /* Copyright (C) 2003 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, 2nd 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 log(double);
15 extern double sqrt(double);
16 extern double pow(double,double);
17
18 void test(double x)
19 {
20   if (sqrt(pow(x,4.0)) != x*x)
21     link_error ();
22
23   if (pow(sqrt(x),4.0) != x*x)
24     link_error ();
25
26   if (pow(pow(x,4.0),0.25) != x)
27     link_error ();
28 }
29
30 void test2(double x, double y, double z)
31 {
32   if (sqrt(pow(x,y)) != pow(x,y*0.5))
33     link_error ();
34
35   if (log(pow(x,y)) != y*log(x))
36     link_error ();
37
38   if (pow(exp(x),y) != exp(x*y))
39     link_error ();
40
41   if (pow(sqrt(x),y) != pow(x,y*0.5))
42     link_error ();
43
44   if (pow(pow(x,y),z) != pow(x,y*z))
45     link_error ();
46 }
47
48 int main()
49 {
50   test (2.0);
51   test2 (2.0, 3.0, 4.0);
52   return 0;
53 }
54