File: xxx-nan.c

package info (click to toggle)
avr-libc 1%3A1.6.2.cvs20080610-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 14,848 kB
  • ctags: 55,619
  • sloc: ansic: 92,267; asm: 6,692; sh: 4,131; makefile: 2,481; python: 976; pascal: 426; perl: 116
file content (74 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download
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
/* Test of a set of functions: func(NaN) --> NaN
   $Id: xxx-nan.c,v 1.2 2007/11/05 11:18:16 dmix Exp $
 */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "progmem.h"

/* Table of tested functions.	*/
double (*tfun[]) (double) = {
    acos,
    asin,
    atan,
    ceil,
    cos,
    cosh,
    exp,
    floor,
    log,
    log10,
    sin,
    sinh,
    sqrt,
    tan,
    tanh,
    trunc,
    round
};

union lofl_u {
    long lo;
    float fl;
};

volatile union lofl_u v = { 1 };

/* Table of test cases: NaNs	*/
PROGMEM const union lofl_u tnan[] = {
    { 0x7f800001 },
    { 0x7f800100 },
    { 0x7f810000 },
    { 0x7fc00000 },
    { 0x7fffffff },
    { 0xff800001 },
    { 0xff800100 },
    { 0xff810000 },
    { 0xffc00000 },
    { 0xffffffff },
};

void x_exit (int index)
{
#ifndef	__AVR__
    fprintf (stderr, "t[%d]:  %#lx\n", index - 1, v.lo);
#endif
    exit (index ? index : -1);
}

int main ()
{
    union lofl_u x;
    int f, n;
    
    for (f = 0; f < (int) (sizeof(tfun)/sizeof(tfun[0])); f++) {
	for (n = 0; n < (int) (sizeof(tnan)/sizeof(tnan[0])); n++) {
	    x.lo = pgm_read_dword (& tnan[n]);
	    v.fl = (tfun[f]) (x.fl);
	    if (!isnan (v.fl)) {
		x_exit (f+1);
	    }
	}
    }
    return 0;
}