OSDN Git Service

gcc/testsuite/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / sh4a-fprun.c
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 void check_f (float res, float expected) {
15   if (res >= expected - 0.001f && res <= expected + 0.001f)
16     return;
17
18   abort ();
19 }
20
21 void check_d (double res, double expected) {
22   if (res >= expected - 0.001 && res <= expected + 0.001)
23     return;
24
25   abort ();
26 }
27
28 int main() {
29   check_f (sqrtf(sqrt_arg), sqrt_res);
30   dg2rad_f = dg2rad_d = atan(1) / 45;
31   check_f (sinf(90*dg2rad_f), 1);
32   check_f (cosf(90*dg2rad_f), 0);
33   check_d (sin(-90*dg2rad_d), -1);
34   check_d (cos(180*dg2rad_d), -1);
35   check_d (sin(-45*dg2rad_d) * cosf(135*dg2rad_f), 0.5);
36   exit (0);
37 }