1  /* Verify that fsca and fssra yield reasonable results.  */
       2  /* This test calls the sinf and cosf library functions for targets other
       3     than sh4a, but the VxWorks kernel doesn't have those functions.  */
       4  /* { dg-do run { target { "sh*-*-*" && { ! vxworks_kernel } } } } */
       5  /* { dg-options "-O -ffast-math" } */
       6  
       7  #include <math.h>
       8  #include <stdlib.h>
       9  
      10  float sqrt_arg = 4.0f, sqrt_res = 2.0f;
      11  float dg2rad_f;
      12  double dg2rad_d;
      13  
      14  float __attribute__ ((noinline))
      15  test_sinf (float x)
      16  {
      17    return sinf (x);
      18  }
      19  
      20  float __attribute ((noinline))
      21  test_cosf (float x)
      22  {
      23    return cosf (x);
      24  }
      25  
      26  void
      27  check_f (float res, float expected)
      28  {
      29    if (res >= expected - 0.001f && res <= expected + 0.001f)
      30      return;
      31  
      32    abort ();
      33  }
      34  
      35  void
      36  check_d (double res, double expected)
      37  {
      38    if (res >= expected - 0.001 && res <= expected + 0.001)
      39      return;
      40  
      41    abort ();
      42  }
      43  
      44  int
      45  main()
      46  {
      47    check_f (sqrtf(sqrt_arg), sqrt_res);
      48    dg2rad_f = dg2rad_d = atan(1) / 45;
      49    check_f (test_sinf(90*dg2rad_f), 1);
      50    check_f (test_cosf(90*dg2rad_f), 0);
      51    check_d (sin(-90*dg2rad_d), -1);
      52    check_d (cos(180*dg2rad_d), -1);
      53    check_d (sin(-45*dg2rad_d) * cosf(135*dg2rad_f), 0.5);
      54    exit (0);
      55  }