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