aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.target/sh/sh4a-fprun.c
blob: e5fbc4acad39a07b3c94c1f4015d1c3a27676ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Verify that fsca and fssra yield reasonable results.  */
/* This test calls the sinf and cosf library functions for targets other
   than sh4a, but the VxWorks kernel doesn't have those functions.  */
/* { dg-do run { target { "sh*-*-*" && { ! vxworks_kernel } } } } */
/* { dg-options "-O -ffast-math" } */

#include <math.h>
#include <stdlib.h>

float sqrt_arg = 4.0f, sqrt_res = 2.0f;
float dg2rad_f;
double dg2rad_d;

float __attribute__ ((noinline))
test_sinf (float x)
{
  return sinf (x);
}

float __attribute ((noinline))
test_cosf (float x)
{
  return cosf (x);
}

void
check_f (float res, float expected)
{
  if (res >= expected - 0.001f && res <= expected + 0.001f)
    return;

  abort ();
}

void
check_d (double res, double expected)
{
  if (res >= expected - 0.001 && res <= expected + 0.001)
    return;

  abort ();
}

int
main()
{
  check_f (sqrtf(sqrt_arg), sqrt_res);
  dg2rad_f = dg2rad_d = atan(1) / 45;
  check_f (test_sinf(90*dg2rad_f), 1);
  check_f (test_cosf(90*dg2rad_f), 0);
  check_d (sin(-90*dg2rad_d), -1);
  check_d (cos(180*dg2rad_d), -1);
  check_d (sin(-45*dg2rad_d) * cosf(135*dg2rad_f), 0.5);
  exit (0);
}