OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [test/] [math.c] - Blame information for rev 862

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
2
  Test the library maths functions using trusted precomputed test
3
  vectors.
4
 
5
  These vectors were originally generated on a sun3 with a 68881 using
6
  80 bit precision, but ...
7
 
8
  Each function is called with a variety of interesting arguments.
9
  Note that many of the polynomials we use behave badly when the
10
  domain is stressed, so the numbers in the vectors depend on what is
11
  useful to test - eg sin(1e30) is pointless - the arg has to be
12
  reduced modulo pi, and after that there's no bits of significance
13
  left to evaluate with - any number would be just as precise as any
14
  other.
15
 
16
 
17
*/
18
 
19
#include "test.h"
20
#include <math.h>
21
#include <ieeefp.h>
22
#include <float.h>
23
#include <math.h>
24
#include <errno.h>
25
#include <stdio.h>
26
 
27
int inacc;
28
 
29
int merror;
30
double mretval = 64;
31
int traperror = 1;
32
char *mname;
33
 
34
int verbose;
35
 
36
/* To test exceptions - we trap them all and return a known value */
37
int
38
_DEFUN(matherr,(e),
39
       struct exception *e)
40
{
41
  if (traperror)
42
  {
43
    merror = e->type + 12;
44
    mname = e->name;
45
    e->retval = mretval;
46
    errno = merror + 24;
47
    return 1;
48
  }
49
  return 0;
50
}
51
 
52
 
53
void _DEFUN(translate_to,(file,r),
54
            FILE *file _AND
55
            double r)
56
{
57
  __ieee_double_shape_type bits;
58
  bits.value = r;
59
  fprintf(file, "0x%08x, 0x%08x", bits.parts.msw, bits.parts.lsw);
60
}
61
 
62
int
63
_DEFUN(ffcheck,( is, p, name, serrno, merror),
64
       double is _AND
65
       one_line_type *p _AND
66
       char *name _AND
67
       int serrno _AND
68
       int merror)
69
{
70
  /* Make sure the answer isn't to far wrong from the correct value */
71
  __ieee_double_shape_type correct, isbits;
72
  int mag;
73
  isbits.value = is;
74
 
75
  correct.parts.msw = p->qs[0].msw;
76
  correct.parts.lsw = p->qs[0].lsw;
77
 
78
  mag = mag_of_error(correct.value, is);
79
 
80
  if (mag < p->error_bit)
81
  {
82
    inacc ++;
83
 
84
    printf("%s:%d, inaccurate answer: bit %d (%08x%08x %08x%08x) (%g %g)\n",
85
           name,  p->line, mag,
86
           correct.parts.msw,
87
           correct.parts.lsw,
88
           isbits.parts.msw,
89
           isbits.parts.lsw,
90
           correct.value, is);
91
  }
92
 
93
#if 0
94
  if (p->qs[0].merror != merror)
95
  {
96
    printf("testing %s_vec.c:%d, matherr wrong: %d %d\n",
97
           name, p->line, merror, p->qs[0].merror);
98
  }
99
 
100
  if (p->qs[0].errno_val != errno)
101
  {
102
    printf("testing %s_vec.c:%d, errno wrong: %d %d\n",
103
           name, p->line, errno, p->qs[0].errno_val);
104
 
105
  }
106
#endif
107
  return mag;
108
}
109
 
110
double
111
_DEFUN(thedouble, (msw, lsw),
112
       long msw _AND
113
       long lsw)
114
{
115
  __ieee_double_shape_type x;
116
 
117
  x.parts.msw = msw;
118
  x.parts.lsw = lsw;
119
  return x.value;
120
}
121
 
122
int calc;
123
int reduce;
124
 
125
 
126
_DEFUN(frontline,(f, mag, p, result, merror, errno, args, name),
127
       FILE *f _AND
128
       int mag _AND
129
       one_line_type *p _AND
130
       double result _AND
131
       int merror _AND
132
       int errno _AND
133
       char *args _AND
134
       char *name)
135
{
136
  if (reduce && p->error_bit < mag)
137
  {
138
    fprintf(f, "{%2d,", p->error_bit);
139
  }
140
  else
141
  {
142
    fprintf(f, "{%2d,",mag);
143
  }
144
 
145
 
146
  fprintf(f,"%2d,%3d,", merror,errno);
147
  fprintf(f, "__LINE__, ");
148
 
149
  if (calc)
150
  {
151
    translate_to(f, result);
152
  }
153
  else
154
  {
155
    translate_to(f, thedouble(p->qs[0].msw, p->qs[0].lsw));
156
  }
157
 
158
  fprintf(f, ", ");
159
 
160
  fprintf(f,"0x%08x, 0x%08x", p->qs[1].msw, p->qs[1].lsw);
161
 
162
 
163
  if (args[2])
164
  {
165
    fprintf(f, ", ");
166
    fprintf(f,"0x%08x, 0x%08x", p->qs[2].msw, p->qs[2].lsw);
167
  }
168
 
169
  fprintf(f,"}, /* %g=f(%g",result,
170
          thedouble(p->qs[1].msw, p->qs[1].lsw));
171
 
172
  if (args[2])
173
  {
174
    fprintf(f,", %g", thedouble(p->qs[2].msw,p->qs[2].lsw));
175
  }
176
  fprintf(f, ")*/\n");
177
}
178
 
179
_DEFUN(finish,(f, vector,  result , p, args, name),
180
       FILE *f _AND
181
       int vector _AND
182
       double result _AND
183
       one_line_type *p _AND
184
       char *args _AND
185
       char *name)
186
{
187
  int mag;
188
 
189
  mag = ffcheck(result, p,name,  merror, errno);
190
  if (vector)
191
  {
192
    frontline(f, mag, p, result, merror, errno, args , name);
193
  }
194
}
195
int redo;
196
 
197
_DEFUN(run_vector_1,(vector, p, func, name, args),
198
       int vector _AND
199
       one_line_type *p _AND
200
       char *func _AND
201
       char *name _AND
202
       char *args)
203
{
204
  FILE *f;
205
  int mag;
206
  double result;
207
 
208
  if (vector)
209
  {
210
 
211
    VECOPEN(name, f);
212
 
213
    if (redo)
214
    {
215
      double k;
216
 
217
      for (k = -.2; k < .2; k+= 0.00132)
218
      {
219
 
220
        fprintf(f,"{1,1, 1,1, 0,0,0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
221
                k,k+4);
222
 
223
      }
224
 
225
      for (k = -1.2; k < 1.2; k+= 0.01)
226
      {
227
 
228
        fprintf(f,"{1,1, 1,1, 0,0,0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
229
                k,k+4);
230
 
231
      }
232
      for (k = -M_PI *2; k < M_PI *2; k+= M_PI/2)
233
      {
234
 
235
        fprintf(f,"{1,1, 1,1, 0,0,0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
236
                k,k+4);
237
 
238
      }
239
 
240
      for (k = -30; k < 30; k+= 1.7)
241
      {
242
 
243
        fprintf(f,"{2,2, 1,1, 0,0, 0x%08x,0x%08x, 0x%08x, 0x%08x},\n",
244
                k,k+4);
245
 
246
      }
247
      VECCLOSE(f, name, args);
248
      return;
249
    }
250
  }
251
 
252
  newfunc(name);
253
  while (p->line)
254
  {
255
    double arg1 = thedouble(p->qs[1].msw, p->qs[1].lsw);
256
    double arg2 = thedouble(p->qs[2].msw, p->qs[2].lsw);
257
 
258
    double r;
259
    double rf;
260
 
261
    errno = 0;
262
    merror = 0;
263
    mname = 0;
264
 
265
 
266
    line(p->line);
267
 
268
    merror = 0;
269
    errno = 123;
270
 
271
    if (strcmp(args,"dd")==0)
272
    {
273
      typedef double _EXFUN((*pdblfunc),(double));
274
 
275
      /* Double function returning a double */
276
 
277
      result = ((pdblfunc)(func))(arg1);
278
 
279
      finish(f,vector, result, p, args, name);
280
    }
281
    else  if (strcmp(args,"ff")==0)
282
    {
283
      float arga;
284
      double a;
285
 
286
      typedef float _EXFUN((*pdblfunc),(float));
287
 
288
      /* Double function returning a double */
289
 
290
      if (arg1 < FLT_MAX )
291
      {
292
        arga = arg1;
293
        result = ((pdblfunc)(func))(arga);
294
        finish(f, vector, result, p,args, name);
295
      }
296
    }
297
    else if (strcmp(args,"ddd")==0)
298
     {
299
       typedef double _EXFUN((*pdblfunc),(double,double));
300
 
301
       result = ((pdblfunc)(func))(arg1,arg2);
302
       finish(f, vector, result, p,args, name);
303
     }
304
     else  if (strcmp(args,"fff")==0)
305
     {
306
       double a,b;
307
 
308
       float arga;
309
       float argb;
310
 
311
       typedef float _EXFUN((*pdblfunc),(float,float));
312
 
313
 
314
       if (arg1 < FLT_MAX && arg2 < FLT_MAX)
315
       {
316
         arga = arg1;
317
         argb = arg2;
318
         result = ((pdblfunc)(func))(arga, argb);
319
         finish(f, vector, result, p,args, name);
320
       }
321
     }
322
     else if (strcmp(args,"did")==0)
323
     {
324
       typedef double _EXFUN((*pdblfunc),(int,double));
325
 
326
       result = ((pdblfunc)(func))((int)arg1,arg2);
327
       finish(f, vector, result, p,args, name);
328
     }
329
     else  if (strcmp(args,"fif")==0)
330
     {
331
       double a,b;
332
 
333
       float arga;
334
       float argb;
335
 
336
       typedef float _EXFUN((*pdblfunc),(int,float));
337
 
338
 
339
       if (arg1 < FLT_MAX && arg2 < FLT_MAX)
340
       {
341
         arga = arg1;
342
         argb = arg2;
343
         result = ((pdblfunc)(func))((int)arga, argb);
344
         finish(f, vector, result, p,args, name);
345
       }
346
     }
347
 
348
    p++;
349
  }
350
  if (vector)
351
  {
352
    VECCLOSE(f, name, args);
353
  }
354
}
355
 
356
void
357
_DEFUN_VOID(test_math)
358
{
359
  test_acos(0);
360
  test_acosf(0);
361
  test_acosh(0);
362
  test_acoshf(0);
363
  test_asin(0);
364
  test_asinf(0);
365
  test_asinh(0);
366
  test_asinhf(0);
367
  test_atan(0);
368
  test_atan2(0);
369
  test_atan2f(0);
370
  test_atanf(0);
371
  test_atanh(0);
372
  test_atanhf(0);
373
  test_ceil(0);
374
  test_ceilf(0);
375
  test_cos(0);
376
  test_cosf(0);
377
  test_cosh(0);
378
  test_coshf(0);
379
  test_erf(0);
380
  test_erfc(0);
381
  test_erfcf(0);
382
  test_erff(0);
383
  test_exp(0);
384
  test_expf(0);
385
  test_fabs(0);
386
  test_fabsf(0);
387
  test_floor(0);
388
  test_floorf(0);
389
  test_fmod(0);
390
  test_fmodf(0);
391
  test_gamma(0);
392
  test_gammaf(0);
393
  test_hypot(0);
394
  test_hypotf(0);
395
  test_j0(0);
396
  test_j0f(0);
397
  test_j1(0);
398
  test_j1f(0);
399
  test_jn(0);
400
  test_jnf(0);
401
  test_log(0);
402
  test_log10(0);
403
  test_log10f(0);
404
  test_log1p(0);
405
  test_log1pf(0);
406
  test_log2(0);
407
  test_log2f(0);
408
  test_logf(0);
409
  test_sin(0);
410
  test_sinf(0);
411
  test_sinh(0);
412
  test_sinhf(0);
413
  test_sqrt(0);
414
  test_sqrtf(0);
415
  test_tan(0);
416
  test_tanf(0);
417
  test_tanh(0);
418
  test_tanhf(0);
419
  test_y0(0);
420
  test_y0f(0);
421
  test_y1(0);
422
  test_y1f(0);
423
  test_y1f(0);
424
  test_ynf(0);
425
}
426
 
427
/* These have to be played with to get to compile on machines which
428
   don't have the fancy <foo>f entry points
429
*/
430
 
431
#if 0
432
float _DEFUN(cosf,(a), float a) { return cos((double)a); }
433
float _DEFUN(sinf,(a), float  a) { return sin((double)a); }
434
float _DEFUN(log1pf,(a), float a) { return log1p((double)a); }
435
float _DEFUN(tanf,(a), float a) { return tan((double)a); }
436
float _DEFUN(ceilf,(a), float a) { return ceil(a); }
437
float _DEFUN(floorf,(a), float a) { return floor(a); }
438
#endif
439
 
440
/*ndef HAVE_FLOAT*/
441
#if 0
442
 
443
float fmodf(a,b) float a,b; { return fmod(a,b); }
444
float hypotf(a,b) float a,b; { return hypot(a,b); }
445
 
446
float acosf(a) float a; { return acos(a); }
447
float acoshf(a) float a; { return acosh(a); }
448
float asinf(a) float a; { return asin(a); }
449
float asinhf(a) float a; { return asinh(a); }
450
float atanf(a) float a; { return atan(a); }
451
float atanhf(a) float a; { return atanh(a); }
452
 
453
float coshf(a) float a; { return cosh(a); }
454
float erff(a) float a; { return erf(a); }
455
float erfcf(a) float a; { return erfc(a); }
456
float expf(a) float a; { return exp(a); }
457
float fabsf(a) float a; { return fabs(a); }
458
 
459
float gammaf(a) float a; { return gamma(a); }
460
float j0f(a) float a; { return j0(a); }
461
float j1f(a) float a; { return j1(a); }
462
float log10f(a) float a; { return log10(a); }
463
 
464
float logf(a) float a; { return log(a); }
465
 
466
float sinhf(a) float a; { return sinh(a); }
467
float sqrtf(a) float a; { return sqrt(a); }
468
 
469
float tanhf(a) float a; { return tanh(a); }
470
float y0f(a) float a; { return y0(a); }
471
float y1f(a) float a; { return y1(a); }
472
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.