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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091031115210-crjd42sn6ezrj52c
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 isinf() function.
2
 
   $Id: isinf-01.c,v 1.1.2.1 2008/03/20 21:42:30 joerg_wunsch Exp $
3
 
 */
4
 
#include <math.h>
5
 
#include <stdio.h>
6
 
#include <stdlib.h>
7
 
#include "progmem.h"
8
 
 
9
 
#ifndef __AVR__
10
 
# define PRINTFLN(fmt, ...)     \
11
 
    printf ("\nLine %d: " fmt "\n", __LINE__, ##__VA_ARGS__)
12
 
# define EXIT(code)     exit ((code) < 255 ? (code) : 100 + (code) % 100)
13
 
#else
14
 
# if defined(__AVR_ATmega128__)
15
 
  /* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
16
 
#  define PRINTFLN(fmt, ...)    \
17
 
    sprintf ((char *)0x2000, "\nLine %d: " fmt "\n", __LINE__, ##__VA_ARGS__)
18
 
# else
19
 
   /* small AVR */
20
 
#  define PRINTFLN(args...)
21
 
# endif
22
 
# define EXIT   exit
23
 
#endif
24
 
 
25
 
union lofl_u {
26
 
    long lo;
27
 
    float fl;
28
 
};
29
 
 
30
 
/* Result is placed into SRAM variable, allocated at the start of
31
 
   memory. This is convinient to debug: read a core dump.       */
32
 
volatile int v = 1;
33
 
 
34
 
PROGMEM const struct {          /* Table of test cases. */
35
 
    union lofl_u x;             /* argument     */
36
 
    int z;                      /* result       */
37
 
} t[] = {
38
 
 
39
 
    /* Zero     */
40
 
    { { .fl= +0.0 },    0 },
41
 
    { { .fl= -0.0 },    0 },
42
 
    
43
 
    /* A few of normal values   */
44
 
    { { 0x00800000 },   0 },
45
 
    { { 0x00800001 },   0 },
46
 
    { { 0x00ffffff },   0 },
47
 
    { { 0x3f800000 },   0 },
48
 
    { { 0x7f7fffff },   0 },
49
 
    { { 0x80800000 },   0 },
50
 
    { { 0x80800001 },   0 },
51
 
    { { 0x80ffffff },   0 },
52
 
    { { 0xdf800000 },   0 },
53
 
    { { 0xff7fffff },   0 },
54
 
    
55
 
    /* Subnormal        */
56
 
    { { 0x00000001 }, 0 },
57
 
    { { 0x00000100 }, 0 },
58
 
    { { 0x00010000 }, 0 },
59
 
    { { 0x007fffff }, 0 },
60
 
    { { 0x80000001 }, 0 },
61
 
    { { 0x80000100 }, 0 },
62
 
    { { 0x80010000 }, 0 },
63
 
    { { 0x807fffff }, 0 },
64
 
 
65
 
    /* Inf      */
66
 
    { { 0x7f800000 },   1 },
67
 
    { { 0xff800000 },  -1 },    
68
 
 
69
 
    /* NaN      */
70
 
    { { 0x7f800001 },   0 },
71
 
    { { 0x7fc00000 },   0 },
72
 
    { { 0x7fffffff },   0 },
73
 
    { { 0xff800001 },   0 },
74
 
    { { 0xffc00000 },   0 },
75
 
    { { 0xffffffff },   0 },
76
 
};
77
 
 
78
 
int main ()
79
 
{
80
 
    union lofl_u x;
81
 
    int z;
82
 
    int i;
83
 
 
84
 
    /* Default implementation.  */    
85
 
    for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
86
 
        x.lo = pgm_read_dword (& t[i].x);
87
 
        z = pgm_read_word (& t[i].z);
88
 
        v = isinf (x.fl);
89
 
        if (v != z) {
90
 
            PRINTFLN ("i= %d  v= %d", i, v);
91
 
            EXIT (i + 1);
92
 
        }
93
 
    }
94
 
 
95
 
#ifdef  __AVR__
96
 
    {
97
 
        int (* volatile vp)(double);
98
 
        /* Force to use the library implementation.     */
99
 
        vp = & isinf;
100
 
        for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
101
 
            x.lo = pgm_read_dword (& t[i].x);
102
 
            z = pgm_read_word (& t[i].z);
103
 
            v = vp (x.fl);
104
 
            if (v != z) {
105
 
                PRINTFLN ("i= %d  v= %d", i, v);
106
 
                EXIT (i + 101);
107
 
            }
108
 
        }
109
 
    }
110
 
#endif
111
 
 
112
 
    return 0;
113
 
}