~ubuntu-branches/ubuntu/raring/avr-libc/raring-proposed

« back to all changes in this revision

Viewing changes to tests/simulate/math/tan-01.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2008-08-10 09:59:16 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080810095916-wwyigh3vt0e9s7ud
Tags: 1:1.6.2.cvs20080610-2
Added build-depends on texlive-extra-utils (closes: #493454)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Test of tan() function.
 
2
   $Id: tan-01.c,v 1.1 2007/02/05 21:35:58 dmix Exp $
 
3
 */
 
4
#include <math.h>
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include "progmem.h"
 
8
 
 
9
union lofl_u {
 
10
    long lo;
 
11
    float fl;
 
12
};
 
13
 
 
14
volatile union lofl_u v = { .lo = 1 };
 
15
 
 
16
PROGMEM const struct {          /* Table of test cases. */
 
17
    union lofl_u x;             /* argument     */
 
18
    union lofl_u z;             /* tan(x)       */
 
19
} t[] = {
 
20
 
 
21
    /* Zero     */
 
22
    { { .fl= +0.0 },    { .fl= +0.0 }   },
 
23
    { { .fl= -0.0 },    { .fl= -0.0 }   },
 
24
    
 
25
    /* Subnormal        */
 
26
    { { 0x00000001 },   { 0x00000001 }  },
 
27
    { { 0x00000100 },   { 0x00000100 }  },
 
28
    { { 0x00010000 },   { 0x00010000 }  },
 
29
    { { 0x007fffff },   { 0x007fffff }  },
 
30
    { { 0x80000001 },   { 0x80000001 }  },
 
31
    { { 0x80000100 },   { 0x80000100 }  },
 
32
    { { 0x80010000 },   { 0x80010000 }  },
 
33
    { { 0x807fffff },   { 0x807fffff }  },
 
34
    
 
35
    /* Arg. too small   */
 
36
    { { 0x00800000 },   { 0x00800000 }  },
 
37
    { { 0x01000000 },   { 0x01000000 }  },
 
38
    { { 0x38000000 },   { 0x38000000 }  },
 
39
    { { 0x38ffffff },   { 0x38ffffff }  },
 
40
    { { 0x80800000 },   { 0x80800000 }  },
 
41
    { { 0x81000000 },   { 0x81000000 }  },
 
42
    { { 0xb8000000 },   { 0xb8000000 }  },
 
43
    { { 0xb8ffffff },   { 0xb8ffffff }  },
 
44
 
 
45
    /* Some values      */
 
46
//    { { .fl=  0.78539816 },  { .fl=  1.0 } },         /* Pi/4 */
 
47
//    { { .fl= -0.78539816 },  { .fl= -1.0 } },
 
48
};
 
49
 
 
50
void x_exit (int index)
 
51
{
 
52
#ifndef __AVR__
 
53
    fprintf (stderr, "t[%d]:  %#lx\n", index - 1, v.lo);
 
54
#endif
 
55
    exit (index ? index : -1);
 
56
}
 
57
 
 
58
int main ()
 
59
{
 
60
    union lofl_u x, z;
 
61
    int i;
 
62
    
 
63
    for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
 
64
        x.lo = pgm_read_dword (& t[i].x);
 
65
        z.lo = pgm_read_dword (& t[i].z);
 
66
        v.fl = tan (x.fl);
 
67
        /* Comparison is integer to verify the zero sign.       */
 
68
        if (v.lo != z.lo)
 
69
            x_exit (i+1);
 
70
    }
 
71
    return 0;
 
72
}