1  /* Copyright (C) 2002, 2003, 2004  Free Software Foundation.
       2  
       3     Verify that built-in math function constant folding of constant
       4     arguments is correctly performed by the compiler.
       5  
       6     Written by Roger Sayle, 16th August 2002.  */
       7  
       8  /* { dg-do link } */
       9  /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
      10  
      11  extern double atan (double);
      12  extern float atanf (float);
      13  extern long double atanl (long double);
      14  extern double cbrt (double);
      15  extern float cbrtf (float);
      16  extern long double cbrtl (long double);
      17  extern double cos (double);
      18  extern float cosf (float);
      19  extern long double cosl (long double);
      20  extern double exp (double);
      21  extern float expf (float);
      22  extern long double expl (long double);
      23  extern double log (double);
      24  extern float logf (float);
      25  extern long double logl (long double);
      26  extern double pow (double, double);
      27  extern float powf (float, float);
      28  extern long double powl (long double, long double);
      29  extern double sin (double);
      30  extern float sinf (float);
      31  extern long double sinl (long double);
      32  extern double sqrt (double);
      33  extern float sqrtf (float);
      34  extern long double sqrtl (long double);
      35  extern double tan (double);
      36  extern float tanf (float);
      37  extern long double tanl (long double);
      38  
      39  /* All references to link_error should go away at compile-time.  */
      40  extern void link_error(void);
      41  
      42  void test (float f, double d, long double ld)
      43  {
      44    if (sqrt (0.0) != 0.0)
      45      link_error ();
      46  
      47    if (sqrt (1.0) != 1.0)
      48      link_error ();
      49  
      50    if (cbrt (0.0) != 0.0)
      51      link_error ();
      52  
      53    if (cbrt (1.0) != 1.0)
      54      link_error ();
      55  
      56    if (cbrt (-1.0) != -1.0)
      57      link_error ();
      58  
      59    if (exp (0.0) != 1.0)
      60      link_error ();
      61  
      62    if (exp (1.0) <= 2.71 || exp (1.0) >= 2.72)
      63      link_error ();
      64  
      65    if (log (1.0) != 0.0)
      66      link_error ();
      67  
      68    if (sin (0.0) != 0.0)
      69      link_error ();
      70  
      71    if (cos (0.0) != 1.0)
      72      link_error ();
      73  
      74    if (tan (0.0) != 0.0)
      75      link_error ();
      76  
      77    if (atan (0.0) != 0.0)
      78      link_error ();
      79  
      80    if (4.0*atan (1.0) <= 3.14 || 4.0*atan (1.0) >= 3.15)
      81      link_error ();
      82  
      83    if (pow (d, 0.0) != 1.0)
      84      link_error ();
      85  
      86    if (pow (1.0, d) != 1.0)
      87      link_error ();
      88  
      89  
      90    if (sqrtf (0.0F) != 0.0F)
      91      link_error ();
      92  
      93    if (sqrtf (1.0F) != 1.0F)
      94      link_error ();
      95  
      96    if (cbrtf (0.0F) != 0.0F)
      97      link_error ();
      98  
      99    if (cbrtf (1.0F) != 1.0F)
     100      link_error ();
     101  
     102    if (cbrtf (-1.0F) != -1.0F)
     103      link_error ();
     104  
     105    if (expf (0.0F) != 1.0F)
     106      link_error ();
     107  
     108    if (expf (1.0F) <= 2.71F || expf (1.0F) >= 2.72F)
     109      link_error ();
     110  
     111    if (logf (1.0F) != 0.0F)
     112      link_error ();
     113  
     114    if (sinf (0.0F) != 0.0F)
     115      link_error ();
     116  
     117    if (cosf (0.0F) != 1.0F)
     118      link_error ();
     119  
     120    if (tanf (0.0F) != 0.0F)
     121      link_error ();
     122  
     123    if (atanf (0.0F) != 0.0F)
     124      link_error ();
     125  
     126    if (4.0F*atanf (1.0F) <= 3.14F || 4.0F*atanf (1.0F) >= 3.15F)
     127      link_error ();
     128  
     129    if (powf (f, 0.0F) != 1.0F)
     130      link_error ();
     131  
     132    if (powf (1.0F, f) != 1.0F)
     133      link_error ();
     134  
     135  
     136    if (sqrtl (0.0L) != 0.0L)
     137      link_error ();
     138  
     139    if (sqrtl (1.0L) != 1.0L)
     140      link_error ();
     141  
     142    if (cbrtl (0.0L) != 0.0L)
     143      link_error ();
     144  
     145    if (cbrtl (1.0L) != 1.0L)
     146      link_error ();
     147  
     148    if (cbrtl (-1.0L) != -1.0L)
     149      link_error ();
     150  
     151    if (expl (0.0L) != 1.0L)
     152      link_error ();
     153  
     154    if (expl (1.0L) <= 2.71L || expl (1.0L) >= 2.72L)
     155      link_error ();
     156  
     157    if (logl (1.0L) != 0.0L)
     158      link_error ();
     159  
     160    if (sinl (0.0L) != 0.0L)
     161      link_error ();
     162  
     163    if (cosl (0.0L) != 1.0L)
     164      link_error ();
     165  
     166    if (tanl (0.0L) != 0.0L)
     167      link_error ();
     168  
     169    if (atanl (0.0) != 0.0L)
     170      link_error ();
     171  
     172    if (4.0L*atanl (1.0L) <= 3.14L || 4.0L*atanl (1.0L) >= 3.15L)
     173      link_error ();
     174  
     175    if (powl (ld, 0.0L) != 1.0L)
     176      link_error ();
     177  
     178    if (powl (1.0L, ld) != 1.0L)
     179      link_error ();
     180  }
     181  
     182  int main()
     183  {
     184    test (3.0, 3.0F, 3.0L);
     185  
     186    return 0;
     187  }