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

« back to all changes in this revision

Viewing changes to tests/simulate/math/cos-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 cos() function.
2
 
   $Id: cos-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;             /* cos(x)       */
19
 
} t[] = {
20
 
 
21
 
    /* Zero     */
22
 
    { { .fl= +0.0 },    { .fl= 1.0 }    },
23
 
    { { .fl= -0.0 },    { .fl= 1.0 }    },
24
 
    
25
 
    /* Subnormal        */
26
 
    { { 0x00000001 },   { .fl= 1.0 }    },
27
 
    { { 0x00000100 },   { .fl= 1.0 }    },
28
 
    { { 0x00010000 },   { .fl= 1.0 }    },
29
 
    { { 0x007fffff },   { .fl= 1.0 }    },
30
 
    { { 0x80000001 },   { .fl= 1.0 }    },
31
 
    { { 0x80000100 },   { .fl= 1.0 }    },
32
 
    { { 0x80010000 },   { .fl= 1.0 }    },
33
 
    { { 0x807fffff },   { .fl= 1.0 }    },
34
 
    
35
 
    /* Arg. too small   */
36
 
    { { 0x00800000 },   { .fl= 1.0 }    },
37
 
    { { 0x01000000 },   { .fl= 1.0 }    },
38
 
    { { 0x107fffff },   { .fl= 1.0 }    },
39
 
    { { 0x80800000 },   { .fl= 1.0 }    },
40
 
    { { 0x81000000 },   { .fl= 1.0 }    },
41
 
    { { 0x907fffff },   { .fl= 1.0 }    },
42
 
 
43
 
    /* Some values      */
44
 
    { { .fl=  3.1415927 },  { .fl= -1.0 } },
45
 
    { { .fl=  6.2831853 },  { .fl=  1.0 } },
46
 
    { { .fl= -3.1415927 },  { .fl= -1.0 } },
47
 
    { { .fl= -6.2831853 },  { .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 = cos (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
 
}