summaryrefslogtreecommitdiff
path: root/libc/math/test-dbl-wrap.c
blob: 07be1dd70a3138338f377b6f9535ec5b3b63a533 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <math.h>
#include <stdio.h>

#define N 4

static int
do_test (int argc, char *argv[])
{
  int i;
  int result = 0;

  const double eps = 0.01, pi = 3.14;
  const double sin_data[N][2]
    = {{0.0, 0.0}, {pi / 6, 0.5}, {pi / 4, 0.707}, {pi / 3, 0.866}};
  const double exp_data[N][2]
    = {{0.0, 1.0}, {0.5, 1.649}, {1.0, 2.718}, {2.718, 15.150}};

  for (i = 0; i < N; ++i)
    {
      double x, y;
      double s1, c1, t1, e1;
      double s2, c2, t2, as2, ac2, at2, e2, l2;

      x = sin_data[i][0];
      s1 = sin_data[i][1];
      c1 = sqrt (1 - s1 * s1);
      t1 = s1 / c1;

      s2 = sin (x);
      c2 = cos (x);
      t2 = tan (x);
      as2 = asin (s1);
      ac2 = acos (c1);
      at2 = atan (t1);

      y = exp_data[i][0];
      e1 = exp_data[i][1];

      e2 = exp (y);
      l2 = log (e1);

      if (fabs (s1 - s2) > eps)
	{
	  result |= 1;
#if PRINT
	  printf ("sin(%.3lf) = %.3lf\n", x, s2);
#endif
	}

      if (fabs (c1 - c2) > eps)
	{
	  result |= 2;
#if PRINT
	  printf ("cos(%.3lf) = %.3lf\n", x, c2);
#endif
	}

      if (fabs (t1 - t2) > eps)
	{
	  result |= 4;
#if PRINT
	  printf ("tan(%.3lf) = %.3lf\n", x, t2);
#endif
	}

      if (fabs (x - as2) > eps)
	{
	  result |= 8;
#if PRINT
	  printf ("asin(%.3lf) = %.3lf\n", s1, as2);
#endif
	}

      if (fabs (x - ac2) > eps)
	{
	  result |= 16;
#if PRINT
	  printf ("acos(%.3lf) = %.3lf\n", c1, ac2);
#endif
	}

      if (fabs (x - at2) > eps)
	{
	  result |= 32;
#if PRINT
	  printf ("atan(%.3lf) = %.3lf\n", t1, at2);
#endif
	}

      if (fabs (e1 - e2) > eps)
	{
	  result |= 64;
#if PRINT
	  printf ("exp(%.3lf) = %.3lf\n", y, e2);
#endif
	}

      if (fabs (y - l2) > eps)
	{
	  result |= 128;
#if PRINT
	  printf ("log(%.3lf) = %.3lf\n", e1, l2);
#endif
	}
    }

  return result;
}

#include "../test-skeleton.c"