|
Szabolcs Nagy |
cfa23c |
#include <fenv.h>
|
|
Szabolcs Nagy |
cfa23c |
#include <float.h>
|
|
Szabolcs Nagy |
cfa23c |
#include <math.h>
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
#undef RN
|
|
Szabolcs Nagy |
cfa23c |
#undef RZ
|
|
Szabolcs Nagy |
cfa23c |
#undef RD
|
|
Szabolcs Nagy |
cfa23c |
#undef RU
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_TONEAREST
|
|
Szabolcs Nagy |
cfa23c |
#define RN FE_TONEAREST
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define RN 0
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_TOWARDZERO
|
|
Szabolcs Nagy |
cfa23c |
#define RZ FE_TOWARDZERO
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define RZ -1
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_DOWNWARD
|
|
Szabolcs Nagy |
cfa23c |
#define RD FE_DOWNWARD
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define RD -1
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_UPWARD
|
|
Szabolcs Nagy |
cfa23c |
#define RU FE_UPWARD
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define RU -1
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
#undef INEXACT
|
|
Szabolcs Nagy |
cfa23c |
#undef INVALID
|
|
Szabolcs Nagy |
cfa23c |
#undef DIVBYZERO
|
|
Szabolcs Nagy |
cfa23c |
#undef UNDERFLOW
|
|
Szabolcs Nagy |
cfa23c |
#undef OVERFLOW
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_INEXACT
|
|
Szabolcs Nagy |
cfa23c |
#define INEXACT FE_INEXACT
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define INEXACT 0
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_INVALID
|
|
Szabolcs Nagy |
cfa23c |
#define INVALID FE_INVALID
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define INVALID 0
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_DIVBYZERO
|
|
Szabolcs Nagy |
cfa23c |
#define DIVBYZERO FE_DIVBYZERO
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define DIVBYZERO 0
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_UNDERFLOW
|
|
Szabolcs Nagy |
cfa23c |
#define UNDERFLOW FE_UNDERFLOW
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define UNDERFLOW 0
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
#ifdef FE_OVERFLOW
|
|
Szabolcs Nagy |
cfa23c |
#define OVERFLOW FE_OVERFLOW
|
|
Szabolcs Nagy |
cfa23c |
#else
|
|
Szabolcs Nagy |
cfa23c |
#define OVERFLOW 0
|
|
Szabolcs Nagy |
cfa23c |
#endif
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
#undef inf
|
|
Szabolcs Nagy |
cfa23c |
#undef nan
|
|
Szabolcs Nagy |
cfa23c |
#define inf INFINITY
|
|
Szabolcs Nagy |
cfa23c |
#define nan NAN
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
#define T(...) {__FILE__, __LINE__, __VA_ARGS__},
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
#define POS char *file; int line;
|
|
Szabolcs Nagy |
cfa23c |
struct d_d {POS int r; double x; double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct f_f {POS int r; float x; float y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct l_l {POS int r; long double x; long double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct ff_f {POS int r; float x; float x2; float y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct dd_d {POS int r; double x; double x2; double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct ll_l {POS int r; long double x; long double x2; long double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct d_di {POS int r; double x; double y; float dy; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct f_fi {POS int r; float x; float y; float dy; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct l_li {POS int r; long double x; long double y; float dy; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct di_d {POS int r; double x; long long i; double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct fi_f {POS int r; float x; long long i; float y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct li_l {POS int r; long double x; long long i; long double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct d_i {POS int r; double x; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct f_i {POS int r; float x; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct l_i {POS int r; long double x; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct d_dd {POS int r; double x; double y; float dy; double y2; float dy2; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct f_ff {POS int r; float x; float y; float dy; float y2; float dy2; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct l_ll {POS int r; long double x; long double y; float dy; long double y2; float dy2; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct ff_fi {POS int r; float x; float x2; float y; float dy; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct dd_di {POS int r; double x; double x2; double y; float dy; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct ll_li {POS int r; long double x; long double x2; long double y; float dy; long long i; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct fff_f {POS int r; float x; float x2; float x3; float y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct ddd_d {POS int r; double x; double x2; double x3; double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
struct lll_l {POS int r; long double x; long double x2; long double x3; long double y; float dy; int e; };
|
|
Szabolcs Nagy |
cfa23c |
#undef POS
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
char *estr(int);
|
|
Szabolcs Nagy |
cfa23c |
char *rstr(int);
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
float ulperr(double got, double want, float dwant);
|
|
Szabolcs Nagy |
cfa23c |
float ulperrf(float got, float want, float dwant);
|
|
Szabolcs Nagy |
cfa23c |
float ulperrl(long double got, long double want, float dwant);
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
static int checkexcept(int got, int want, int r)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
if (r == RN)
|
|
Szabolcs Nagy |
cda5e0 |
#if defined CHECK_INEXACT
|
|
Szabolcs Nagy |
cda5e0 |
return got == want;
|
|
Szabolcs Nagy |
cda5e0 |
#elif defined CHECK_INEXACT_OMISSION
|
|
Szabolcs Nagy |
cfa23c |
return got == want || got == (want|INEXACT);
|
|
Szabolcs Nagy |
cda5e0 |
#else
|
|
Szabolcs Nagy |
cda5e0 |
return (got|INEXACT) == (want|INEXACT);
|
|
Szabolcs Nagy |
cda5e0 |
#endif
|
|
Szabolcs Nagy |
cfa23c |
return (got|INEXACT|UNDERFLOW) == (want|INEXACT|UNDERFLOW);
|
|
Szabolcs Nagy |
cfa23c |
}
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cda5e0 |
static int checkexceptall(int got, int want, int r)
|
|
Szabolcs Nagy |
cda5e0 |
{
|
|
Szabolcs Nagy |
cda5e0 |
return got == want;
|
|
Szabolcs Nagy |
cda5e0 |
}
|
|
Szabolcs Nagy |
cda5e0 |
|
|
Szabolcs Nagy |
cfa23c |
static int checkulp(float d, int r)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
// TODO: we only care about >=1.5 ulp errors for now, should be 1.0
|
|
Szabolcs Nagy |
cfa23c |
if (r == RN)
|
|
Szabolcs Nagy |
cfa23c |
return fabsf(d) < 1.5;
|
|
Szabolcs Nagy |
75543c |
// accept larger error in non-nearest rounding mode
|
|
Szabolcs Nagy |
75543c |
return fabsf(d) < 3.0;
|
|
Szabolcs Nagy |
cfa23c |
}
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
static int checkcr(long double y, long double ywant, int r)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
if (isnan(ywant))
|
|
Szabolcs Nagy |
cfa23c |
return isnan(y);
|
|
Szabolcs Nagy |
cfa23c |
return y == ywant && signbit(y) == signbit(ywant);
|
|
Szabolcs Nagy |
cfa23c |
}
|
|
Szabolcs Nagy |
cfa23c |
|