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

« back to all changes in this revision

Viewing changes to tests/simulate/math/cosh-02.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 cosh() function.
2
 
   $Id: cosh-02.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;             /* cosh(x)      */
19
 
    unsigned int maxulp;        /* max possible error in ULP    */
20
 
} t[] = {
21
 
 
22
 
    { { .fl= 0 },       { .fl= 1 },             0 },
23
 
    { { .fl= 1 },       { .fl= 1.5430806 },     1 },
24
 
    { { .fl= 2 },       { .fl= 3.7621957 },     1 },
25
 
    { { .fl= 5 },       { .fl= 74.209949 },     2 },
26
 
    { { .fl= 10 },      { .fl= 11013.233 },     7 },
27
 
    { { .fl= 20 },      { .fl= 2.4258260e+8 },  20 },
28
 
    { { .fl= 50 },      { .fl= 2.5923527e+21 }, 20 },
29
 
    { { .fl= 85 },      { .fl= 4.1115063e+36 }, 40 },
30
 
    { { .fl= 89.25 },   { .fl= 2.8823884e+38 }, 50 },
31
 
};
32
 
 
33
 
void x_exit (int index)
34
 
{
35
 
#ifndef __AVR__
36
 
    fprintf (stderr, "t[%d]:  %#lx\n", index - 1, v.lo);
37
 
#endif
38
 
    exit (index ? index : -1);
39
 
}
40
 
 
41
 
int main ()
42
 
{
43
 
    union lofl_u x, z;
44
 
    unsigned int maxulp;
45
 
    unsigned long v1, z1, r;
46
 
    int i;
47
 
    
48
 
    for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
49
 
        x.lo = pgm_read_dword (& t[i].x);
50
 
        z.lo = pgm_read_dword (& t[i].z);
51
 
        maxulp = pgm_read_word (& t[i].maxulp);
52
 
        v.fl = cosh (x.fl);
53
 
        
54
 
        v1 = (v.lo < 0) ? (unsigned long)~(v.lo) : v.lo + 0x80000000;
55
 
        z1 = (z.lo < 0) ? (unsigned long)~(z.lo) : z.lo + 0x80000000;
56
 
        r = (v1 >= z1) ? v1 - z1 : z1 - v1;
57
 
        
58
 
        if (r > maxulp) x_exit (i+1);
59
 
    }
60
 
    return 0;
61
 
}