~ubuntu-branches/ubuntu/maverick/avr-libc/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.1.8 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091031115210-x0mlijnegkce86fk
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test of sin() function.
2
 
   $Id: sin-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;             /* sin(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=  1.5707963 },  { .fl=  1.0 } },
47
 
    { { .fl=  4.7123890 },  { .fl= -1.0 } },
48
 
    { { .fl= -1.5707963 },  { .fl= -1.0 } },
49
 
    { { .fl= -4.7123890 },  { .fl=  1.0 } },
50
 
 
51
 
};
52
 
 
53
 
void x_exit (int index)
54
 
{
55
 
#ifndef __AVR__
56
 
    fprintf (stderr, "t[%d]:  %#lx\n", index - 1, v.lo);
57
 
#endif
58
 
    exit (index ? index : -1);
59
 
}
60
 
 
61
 
int main ()
62
 
{
63
 
    union lofl_u x, z;
64
 
    int i;
65
 
    
66
 
    for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
67
 
        x.lo = pgm_read_dword (& t[i].x);
68
 
        z.lo = pgm_read_dword (& t[i].z);
69
 
        v.fl = sin (x.fl);
70
 
        /* Comparison is integer to verify the zero sign.       */
71
 
        if (v.lo != z.lo)
72
 
            x_exit (i+1);
73
 
    }
74
 
    return 0;
75
 
}