File: sinh-01.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 (87 lines) | stat: -rw-r--r-- 2,183 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
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Test of sinh() function.
   $Id: sinh-01.c,v 1.1 2007/02/05 21:35:58 dmix Exp $
 */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "progmem.h"

union lofl_u {
    long lo;
    float fl;
};

volatile union lofl_u v = { .lo = 1 };

PROGMEM const struct {		/* Table of test cases.	*/
    union lofl_u x;		/* argument	*/
    union lofl_u z;		/* sinh(x)	*/
} t[] = {

    /* Zero	*/
    { { .fl=  0.0 },	{ .fl=  0.0 } },
    { { .fl= -0.0 },	{ .fl= -0.0 } },

    /* Inf	*/
    { { 0x7f800000 },	{ 0x7f800000 } },
    { { 0xff800000 },	{ 0xff800000 } },

    /* Subnormal	*/
    { { 0x00000001 },	{ 0x00000001 } },
    { { 0x00000100 },	{ 0x00000100 } },
    { { 0x00010000 },	{ 0x00010000 } },
    { { 0x007fffff },	{ 0x007fffff } },
    { { 0x80000001 },	{ 0x80000001 } },
    { { 0x80000100 },	{ 0x80000100 } },
    { { 0x80010000 },	{ 0x80010000 } },
    { { 0x807fffff },	{ 0x807fffff } },
    
    /* Arg too big	*/
    { { .fl= 89.415989 },	{ 0x7f800000 } },
    { { .fl= 100 },		{ 0x7f800000 } },
    { { .fl= 1000 },		{ 0x7f800000 } },
    { { 0x7f7fffff },		{ 0x7f800000 } },

    /* Arg too negative	*/
    { { .fl= -89.415989 },	{ 0xff800000 } },
    { { .fl= -100 },		{ 0xff800000 } },
    { { .fl= -12345 },		{ 0xff800000 } },
    { { 0xff7fffff },		{ 0xff800000 } },

    /* Near 0.0	*/
    { { 0x00800000 },	{ 0x00800000 } },
    { { 0x01000000 },	{ 0x01000000 } },
    { { 0x38000000 },	{ 0x38000000 } },
    { { 0x39000000 },	{ 0x39000000 } },
    { { 0x39800000 },	{ 0x39800000 } },

    { { 0x80800000 },	{ 0x80800000 } },
    { { 0x81000000 },	{ 0x81000000 } },
    { { 0xb8000000 },	{ 0xb8000000 } },
    { { 0xb9000000 },	{ 0xb9000000 } },
    { { 0xb9800000 },	{ 0xb9800000 } },
};

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, z;
    int i;
    
    for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
	x.lo = pgm_read_dword (& t[i].x);
	z.lo = pgm_read_dword (& t[i].z);
	v.fl = sinh (x.fl);
	/* Comparison is integer to verify the zero sign.	*/
	if (v.lo != z.lo)
	    x_exit (i+1);
    }
    return 0;
}