|
nsz |
1e5c50 |
#include <stdio.h>
|
|
nsz |
1e5c50 |
#include <math.h>
|
|
nsz |
1e5c50 |
#include "test.h"
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
static struct {
|
|
nsz |
1e5c50 |
float f;
|
|
nsz |
1e5c50 |
int class;
|
|
nsz |
1e5c50 |
} tf[] = {
|
|
nsz |
1e5c50 |
0.0/0.0, FP_NAN,
|
|
nsz |
1e5c50 |
-0.0/0.0, FP_NAN,
|
|
nsz |
1e5c50 |
1/0.0, FP_INFINITE,
|
|
nsz |
1e5c50 |
-1/0.0, FP_INFINITE,
|
|
nsz |
1e5c50 |
0x1.ffffp127, FP_NORMAL,
|
|
nsz |
1e5c50 |
-0x1.ffffp127, FP_NORMAL,
|
|
nsz |
1e5c50 |
0x1p-127, FP_SUBNORMAL,
|
|
nsz |
1e5c50 |
-0x1p-127, FP_SUBNORMAL,
|
|
nsz |
1e5c50 |
0.0, FP_ZERO,
|
|
nsz |
1e5c50 |
-0.0, FP_ZERO,
|
|
nsz |
1e5c50 |
3.14, FP_NORMAL,
|
|
nsz |
1e5c50 |
-42, FP_NORMAL,
|
|
nsz |
1e5c50 |
};
|
|
nsz |
1e5c50 |
static int ntf = sizeof tf / sizeof *tf;
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
static struct {
|
|
nsz |
1e5c50 |
double f;
|
|
nsz |
1e5c50 |
int class;
|
|
nsz |
1e5c50 |
} td[] = {
|
|
nsz |
1e5c50 |
0.0/0.0, FP_NAN,
|
|
nsz |
1e5c50 |
-0.0/0.0, FP_NAN,
|
|
nsz |
1e5c50 |
1/0.0, FP_INFINITE,
|
|
nsz |
1e5c50 |
-1/0.0, FP_INFINITE,
|
|
nsz |
1e5c50 |
0x1.ffffp1023, FP_NORMAL,
|
|
nsz |
1e5c50 |
-0x1.ffffp1023, FP_NORMAL,
|
|
nsz |
1e5c50 |
0x1p-1023, FP_SUBNORMAL,
|
|
nsz |
1e5c50 |
-0x1p-1023, FP_SUBNORMAL,
|
|
nsz |
1e5c50 |
0.0, FP_ZERO,
|
|
nsz |
1e5c50 |
-0.0, FP_ZERO,
|
|
nsz |
1e5c50 |
3.14, FP_NORMAL,
|
|
nsz |
1e5c50 |
-42, FP_NORMAL,
|
|
nsz |
1e5c50 |
};
|
|
nsz |
1e5c50 |
static int ntd = sizeof td / sizeof *td;
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
static struct {
|
|
nsz |
1e5c50 |
long double f;
|
|
nsz |
1e5c50 |
int class;
|
|
nsz |
1e5c50 |
} tl[] = {
|
|
nsz |
1e5c50 |
0.0/0.0, FP_NAN,
|
|
nsz |
1e5c50 |
-0.0/0.0, FP_NAN,
|
|
nsz |
1e5c50 |
1/0.0, FP_INFINITE,
|
|
nsz |
1e5c50 |
-1/0.0, FP_INFINITE,
|
|
nsz |
1e5c50 |
0x1.ffffp16383L, FP_NORMAL,
|
|
nsz |
1e5c50 |
-0x1.ffffp16383L, FP_NORMAL,
|
|
nsz |
1e5c50 |
0x1p-16383L, FP_SUBNORMAL,
|
|
nsz |
1e5c50 |
-0x1p-16383L, FP_SUBNORMAL,
|
|
nsz |
1e5c50 |
0.0, FP_ZERO,
|
|
nsz |
1e5c50 |
-0.0, FP_ZERO,
|
|
nsz |
1e5c50 |
3.14, FP_NORMAL,
|
|
nsz |
1e5c50 |
-42, FP_NORMAL,
|
|
nsz |
1e5c50 |
};
|
|
nsz |
1e5c50 |
static int ntl = sizeof tl / sizeof *tl;
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
void test_fpclassify()
|
|
nsz |
1e5c50 |
{
|
|
nsz |
1e5c50 |
int i;
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
for (i = 0; i < ntf; i++) {
|
|
nsz |
1e5c50 |
if (fpclassify(tf[i].f) != tf[i].class)
|
|
nsz |
1e5c50 |
error("%a want class %d got %d\n", tf[i].f, tf[i].class, fpclassify(tf[i].f));
|
|
nsz |
1e5c50 |
if (!!isinf(tf[i].f) != (tf[i].class == FP_INFINITE))
|
|
nsz |
1e5c50 |
error("%a want class %d got isinf %d\n", tf[i].f, tf[i].class, isinf(tf[i].f));
|
|
nsz |
1e5c50 |
if (!!isnan(tf[i].f) != (tf[i].class == FP_NAN))
|
|
nsz |
1e5c50 |
error("%a want class %d got isnan %d\n", tf[i].f, tf[i].class, isnan(tf[i].f));
|
|
nsz |
1e5c50 |
if (!!isnormal(tf[i].f) != (tf[i].class == FP_NORMAL))
|
|
nsz |
1e5c50 |
error("%a want class %d got isnormal %d\n", tf[i].f, tf[i].class, isnormal(tf[i].f));
|
|
nsz |
1e5c50 |
if (!!isfinite(tf[i].f) != (tf[i].class > FP_INFINITE))
|
|
nsz |
1e5c50 |
error("%a want class %d got isfinite %d\n", tf[i].f, tf[i].class, isfinite(tf[i].f));
|
|
nsz |
1e5c50 |
}
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
for (i = 0; i < ntd; i++) {
|
|
nsz |
1e5c50 |
if (fpclassify(td[i].f) != td[i].class)
|
|
nsz |
1e5c50 |
error("%a want class %d got %d\n", td[i].f, td[i].class, fpclassify(td[i].f));
|
|
nsz |
1e5c50 |
if (!!isinf(td[i].f) != (td[i].class == FP_INFINITE))
|
|
nsz |
1e5c50 |
error("%a want class %d got isinf %d\n", td[i].f, td[i].class, isinf(td[i].f));
|
|
nsz |
1e5c50 |
if (!!isnan(td[i].f) != (td[i].class == FP_NAN))
|
|
nsz |
1e5c50 |
error("%a want class %d got isnan %d\n", td[i].f, td[i].class, isnan(td[i].f));
|
|
nsz |
1e5c50 |
if (!!isnormal(td[i].f) != (td[i].class == FP_NORMAL))
|
|
nsz |
1e5c50 |
error("%a want class %d got isnormal %d\n", td[i].f, td[i].class, isnormal(td[i].f));
|
|
nsz |
1e5c50 |
if (!!isfinite(td[i].f) != (td[i].class > FP_INFINITE))
|
|
nsz |
1e5c50 |
error("%a want class %d got isfinite %d\n", td[i].f, td[i].class, isfinite(td[i].f));
|
|
nsz |
1e5c50 |
}
|
|
nsz |
1e5c50 |
|
|
nsz |
1e5c50 |
for (i = 0; i < ntl; i++) {
|
|
nsz |
1e5c50 |
if (fpclassify(tl[i].f) != tl[i].class)
|
|
nsz |
1e5c50 |
error("%La want class %d got %d\n", tl[i].f, tl[i].class, fpclassify(tl[i].f));
|
|
nsz |
1e5c50 |
if (!!isinf(tl[i].f) != (tl[i].class == FP_INFINITE))
|
|
nsz |
1e5c50 |
error("%La want class %d got isinf %d\n", tl[i].f, tl[i].class, isinf(tl[i].f));
|
|
nsz |
1e5c50 |
if (!!isnan(tl[i].f) != (tl[i].class == FP_NAN))
|
|
nsz |
1e5c50 |
error("%La want class %d got isnan %d\n", tl[i].f, tl[i].class, isnan(tl[i].f));
|
|
nsz |
1e5c50 |
if (!!isnormal(tl[i].f) != (tl[i].class == FP_NORMAL))
|
|
nsz |
1e5c50 |
error("%La want class %d got isnormal %d\n", tl[i].f, tl[i].class, isnormal(tl[i].f));
|
|
nsz |
1e5c50 |
if (!!isfinite(tl[i].f) != (tl[i].class > FP_INFINITE))
|
|
nsz |
1e5c50 |
error("%La want class %d got isfinite %d\n", tl[i].f, tl[i].class, isfinite(tl[i].f));
|
|
nsz |
1e5c50 |
}
|
|
nsz |
1e5c50 |
}
|