|
nsz |
0c7d46 |
#include <stdio.h>
|
|
nsz |
0c7d46 |
#include <math.h>
|
|
nsz |
0c7d46 |
#include "test.h"
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
static int check(double a, double b)
|
|
nsz |
0c7d46 |
{
|
|
nsz |
0c7d46 |
double d = a - b;
|
|
nsz |
0c7d46 |
return fabs(d) <= 0x1p-52*fabs(a);
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
static int checkf(float a, float b)
|
|
nsz |
0c7d46 |
{
|
|
nsz |
0c7d46 |
float d = a - b;
|
|
nsz |
0c7d46 |
return fabsf(d) <= 0x1p-23*fabsf(a);
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
static int checkl(long double a, long double b)
|
|
nsz |
0c7d46 |
{
|
|
nsz |
0c7d46 |
long double d = a - b;
|
|
nsz |
0c7d46 |
return fabsl(d) <= 0x1p-63L*fabsl(a);
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
#define D(fx, y) do{ \
|
|
nsz |
0c7d46 |
double yy = fx; \
|
|
nsz |
0c7d46 |
if (!check(yy, y)) \
|
|
nsz |
0c7d46 |
error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \
|
|
nsz |
0c7d46 |
}while(0)
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
#define F(fx, y) do{ \
|
|
nsz |
0c7d46 |
float yy = fx; \
|
|
nsz |
0c7d46 |
if (!checkf(yy, y)) \
|
|
nsz |
0c7d46 |
error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \
|
|
nsz |
0c7d46 |
}while(0)
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
#define L(fx, y) do{ \
|
|
nsz |
0c7d46 |
long double yy = fx; \
|
|
nsz |
0c7d46 |
if (!checkl(yy, y)) \
|
|
nsz |
0c7d46 |
error("%s got %La = %.21Le want %La = %.21Le\n", #fx, yy, yy, y, y); \
|
|
nsz |
0c7d46 |
}while(0)
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
#define I(fx, y) do{ \
|
|
nsz |
0c7d46 |
int yy = fx; \
|
|
nsz |
0c7d46 |
if (yy != y) \
|
|
nsz |
0c7d46 |
error("%s got %d want %d\n", #fx, yy, y); \
|
|
nsz |
0c7d46 |
}while(0)
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
#define IL(fx, y) do{ \
|
|
nsz |
0c7d46 |
long yy = fx; \
|
|
nsz |
0c7d46 |
if (yy != y) \
|
|
nsz |
0c7d46 |
error("%s got %ld want %ld\n", #fx, yy, y); \
|
|
nsz |
0c7d46 |
}while(0)
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
#define ILL(fx, y) do{ \
|
|
nsz |
0c7d46 |
long long yy = fx; \
|
|
nsz |
0c7d46 |
if (yy != y) \
|
|
nsz |
0c7d46 |
error("%s got %lld want %lld\n", #fx, yy, y); \
|
|
nsz |
0c7d46 |
}while(0)
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
int test_math_sanity()
|
|
nsz |
0c7d46 |
{
|
|
nsz |
0c7d46 |
int i;
|
|
nsz |
0c7d46 |
double q;
|
|
nsz |
0c7d46 |
float qf;
|
|
nsz |
0c7d46 |
long double ql;
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
D(acos(0.7), 0x1.973e83f5d5c9bp-1);
|
|
nsz |
0c7d46 |
F(acosf(0.7f), 0x1.973e84p-1);
|
|
nsz |
0c7d46 |
L(acosl(0.7L), 0x1.973e83f5d5c9aaf8p-1L);
|
|
nsz |
0c7d46 |
D(acosh(1.7), 0x1.1f8c10d010fe6p+0);
|
|
nsz |
0c7d46 |
F(acoshf(1.7f), 0x1.1f8c12p+0);
|
|
nsz |
0c7d46 |
L(acoshl(1.7L), 0x1.1f8c10d010fe5d96p+0L);
|
|
nsz |
0c7d46 |
D(asin(0.7), 0x1.8d00e692afd95p-1);
|
|
nsz |
0c7d46 |
F(asinf(0.7f), 0x1.8d00e6p-1);
|
|
nsz |
0c7d46 |
L(asinl(0.7L), 0x1.8d00e692afd95ddap-1L);
|
|
nsz |
0c7d46 |
D(asinh(0.7), 0x1.4e2a4fe9085ddp-1);
|
|
nsz |
0c7d46 |
F(asinhf(0.7f), 0x1.4e2a5p-1);
|
|
nsz |
0c7d46 |
L(asinhl(0.7L), 0x1.4e2a4fe9085dd732p-1L);
|
|
nsz |
0c7d46 |
D(atan(0.7), 0x1.38b112d7bd4adp-1);
|
|
nsz |
0c7d46 |
F(atanf(0.7f), 0x1.38b112p-1);
|
|
nsz |
0c7d46 |
L(atanl(0.7L), 0x1.38b112d7bd4ad786p-1L);
|
|
nsz |
0c7d46 |
D(atan2(0.7, 1.0), 0x1.38b112d7bd4adp-1);
|
|
nsz |
0c7d46 |
F(atan2f(0.7f, 1.0f), 0x1.38b112p-1);
|
|
nsz |
0c7d46 |
L(atan2l(0.7L, 1.0L), 0x1.38b112d7bd4ad786p-1L);
|
|
nsz |
0c7d46 |
D(atanh(0.7), 0x1.bc0ed0947fbe8p-1);
|
|
nsz |
0c7d46 |
F(atanhf(0.7f), 0x1.bc0edp-1);
|
|
nsz |
0c7d46 |
L(atanhl(0.7L), 0x1.bc0ed0947fbe9068p-1L);
|
|
nsz |
0c7d46 |
D(cbrt(0.7), 0x1.c69b5a72f1a99p-1);
|
|
nsz |
0c7d46 |
F(cbrtf(0.7f), 0x1.c69b5ap-1);
|
|
nsz |
0c7d46 |
L(cbrtl(0.7L), 0x1.c69b5a72f1a99902p-1L);
|
|
nsz |
0c7d46 |
D(ceil(0.7), 0x1p+0);
|
|
nsz |
0c7d46 |
F(ceilf(0.7f), 0x1p+0);
|
|
nsz |
0c7d46 |
L(ceill(0.7L), 0x1p+0L);
|
|
nsz |
0c7d46 |
D(copysign(0.7, -1.0), -0x1.6666666666666p-1);
|
|
nsz |
0c7d46 |
F(copysignf(0.7f, -1.0f), -0x1.666666p-1);
|
|
nsz |
0c7d46 |
L(copysignl(0.7L, -1.0L), -0x1.6666666666666666p-1L);
|
|
nsz |
0c7d46 |
D(cos(0.7), 0x1.87996529f9d93p-1);
|
|
nsz |
0c7d46 |
F(cosf(0.7f), 0x1.879966p-1);
|
|
nsz |
0c7d46 |
L(cosl(0.7L), 0x1.87996529f9d92618p-1L);
|
|
nsz |
0c7d46 |
D(cosh(0.7), 0x1.4152c1862342fp+0);
|
|
nsz |
0c7d46 |
F(coshf(0.7f), 0x1.4152c2p+0);
|
|
nsz |
0c7d46 |
L(coshl(0.7L), 0x1.4152c1862342ef8ep+0L);
|
|
nsz |
0c7d46 |
D(erf(0.7), 0x1.5b08c21171646p-1);
|
|
nsz |
0c7d46 |
F(erff(0.7f), 0x1.5b08c2p-1);
|
|
nsz |
0c7d46 |
L(erfl(0.7L), 0x1.5b08c21171646544p-1L);
|
|
nsz |
0c7d46 |
D(erfc(0.7), 0x1.49ee7bdd1d374p-2);
|
|
nsz |
0c7d46 |
F(erfcf(0.7f), 0x1.49ee7cp-2);
|
|
nsz |
0c7d46 |
L(erfcl(0.7L), 0x1.49ee7bdd1d373576p-2L);
|
|
nsz |
0c7d46 |
D(exp(0.7), 0x1.01c2a61268987p+1);
|
|
nsz |
0c7d46 |
F(expf(0.7f), 0x1.01c2a6p+1);
|
|
nsz |
0c7d46 |
L(expl(0.7L), 0x1.01c2a61268986bfep+1L);
|
|
nsz |
0c7d46 |
D(exp2(0.7), 0x1.9fdf8bcce533dp+0);
|
|
nsz |
0c7d46 |
F(exp2f(0.7f), 0x1.9fdf8cp+0);
|
|
nsz |
0c7d46 |
L(exp2l(0.7L), 0x1.9fdf8bcce533d72p+0L);
|
|
nsz |
0c7d46 |
D(expm1(0.7), 0x1.03854c24d130dp+0);
|
|
nsz |
0c7d46 |
F(expm1f(0.7f), 0x1.03854cp+0);
|
|
nsz |
0c7d46 |
L(expm1l(0.7L), 0x1.03854c24d130d7fep+0L);
|
|
nsz |
0c7d46 |
D(fabs(-0.7), 0x1.6666666666666p-1);
|
|
nsz |
0c7d46 |
F(fabsf(-0.7f), 0x1.666666p-1);
|
|
nsz |
0c7d46 |
L(fabsl(-0.7L), 0x1.6666666666666666p-1L);
|
|
nsz |
0c7d46 |
D(fdim(0.7, 0.5), 0x1.9999999999998p-3);
|
|
nsz |
0c7d46 |
F(fdimf(0.7f, 0.5f), 0x1.999998p-3);
|
|
nsz |
0c7d46 |
L(fdiml(0.7L, 0.5L), 0x1.9999999999999998p-3L);
|
|
nsz |
0c7d46 |
D(floor(0.7), 0x0p+0);
|
|
nsz |
0c7d46 |
F(floorf(0.7f), 0x0p+0);
|
|
nsz |
0c7d46 |
L(floorl(0.7L), 0x0p+0L);
|
|
nsz |
0c7d46 |
D(fma(0.7, 2.0, 0.1), 0x1.8p+0);
|
|
nsz |
0c7d46 |
F(fmaf(0.7f, 2.0f, 0.1f), 0x1.8p+0);
|
|
nsz |
0c7d46 |
L(fmal(0.7L, 2.0L, 0.1L), 0x1.8p+0L);
|
|
nsz |
0c7d46 |
D(fmax(0.7, 0.5), 0x1.6666666666666p-1);
|
|
nsz |
0c7d46 |
F(fmaxf(0.7f, 0.5), 0x1.666666p-1);
|
|
nsz |
0c7d46 |
L(fmaxl(0.7L, 0.5), 0x1.6666666666666666p-1L);
|
|
nsz |
0c7d46 |
D(fmin(0.7, 0.5), 0x1p-1);
|
|
nsz |
0c7d46 |
F(fminf(0.7f, 0.5f), 0x1p-1);
|
|
nsz |
0c7d46 |
L(fminl(0.7L, 0.5L), 0x1p-1L);
|
|
nsz |
0c7d46 |
D(fmod(0.7, 0.5), 0x1.9999999999998p-3);
|
|
nsz |
0c7d46 |
F(fmodf(0.7f, 0.5f), 0x1.999998p-3);
|
|
nsz |
0c7d46 |
L(fmodl(0.7L, 0.5L), 0x1.9999999999999998p-3L);
|
|
nsz |
0c7d46 |
D(frexp(0.7, &i), 0x1.6666666666666p-1);
|
|
nsz |
0c7d46 |
F(frexpf(0.7f, &i), 0x1.666666p-1);
|
|
nsz |
0c7d46 |
L(frexpl(0.7L, &i), 0x1.6666666666666666p-1L);
|
|
nsz |
0c7d46 |
D(hypot(0.7, 1.0), 0x1.387ce204a35d2p+0);
|
|
nsz |
0c7d46 |
F(hypotf(0.7f, 1.0f), 0x1.387ce2p+0);
|
|
nsz |
0c7d46 |
L(hypotl(0.7L, 1.0L), 0x1.387ce204a35d1ff6p+0L);
|
|
nsz |
0c7d46 |
I(ilogb(0.7), -1);
|
|
nsz |
0c7d46 |
I(ilogbf(0.7f), -1);
|
|
nsz |
0c7d46 |
I(ilogbl(0.7L), -1);
|
|
nsz |
0c7d46 |
D(j0(0.7), 0x1.c32cc34b8cc59p-1);
|
|
nsz |
0c7d46 |
F(j0f(0.7f), 0x1.c32cc4p-1);
|
|
nsz |
0c7d46 |
D(j1(0.7), 0x1.50e44279c0546p-2);
|
|
nsz |
0c7d46 |
F(j1f(0.7f), 0x1.50e442p-2);
|
|
nsz |
0c7d46 |
D(jn(2, 0.7), 0x1.e195286f3b2fbp-5);
|
|
nsz |
0c7d46 |
F(jnf(2, 0.7f), 0x1.e19528p-5);
|
|
nsz |
0c7d46 |
D(ldexp(0.7, 3), 0x1.6666666666666p+2);
|
|
nsz |
0c7d46 |
F(ldexpf(0.7f, 3), 0x1.666666p+2);
|
|
nsz |
0c7d46 |
L(ldexpl(0.7L, 3), 0x1.6666666666666666p+2L);
|
|
nsz |
0c7d46 |
D(lgamma(0.7), 0x1.0b20c891cde73p-2);
|
|
nsz |
0c7d46 |
F(lgammaf(0.7f), 0x1.0b20cap-2);
|
|
nsz |
0c7d46 |
L(lgammal(0.7L), 0x1.0b20c891cde72846p-2L);
|
|
nsz |
0c7d46 |
D(lgamma_r(0.7, &i), 0x1.0b20c891cde73p-2);
|
|
nsz |
0c7d46 |
F(lgammaf_r(0.7f, &i), 0x1.0b20cap-2);
|
|
nsz |
0c7d46 |
L(lgammal_r(0.7L, &i), 0x1.0b20c891cde72846p-2L);
|
|
nsz |
0c7d46 |
ILL(llrint(0.7), 1);
|
|
nsz |
0c7d46 |
ILL(llrintf(0.7f), 1);
|
|
nsz |
0c7d46 |
ILL(llrintl(0.7l), 1);
|
|
nsz |
0c7d46 |
ILL(llround(0.7), 1);
|
|
nsz |
0c7d46 |
ILL(llroundf(0.7f), 1);
|
|
nsz |
0c7d46 |
ILL(llroundl(0.7L), 1);
|
|
nsz |
0c7d46 |
D(log(0.7), -0x1.6d3c324e13f5p-2);
|
|
nsz |
0c7d46 |
F(logf(0.7f), -0x1.6d3c34p-2);
|
|
nsz |
0c7d46 |
L(logl(0.7L), -0x1.6d3c324e13f4ec54p-2L);
|
|
nsz |
0c7d46 |
D(log10(0.7), -0x1.3d3d3d21ccf04p-3);
|
|
nsz |
0c7d46 |
F(log10f(0.7f), -0x1.3d3d3ep-3);
|
|
nsz |
0c7d46 |
L(log10l(0.7L), -0x1.3d3d3d21ccf035a6p-3L);
|
|
nsz |
0c7d46 |
D(log1p(0.7), 0x1.0fae81914a991p-1);
|
|
nsz |
0c7d46 |
F(log1pf(0.7f), 0x1.0fae82p-1);
|
|
nsz |
0c7d46 |
L(log1pl(0.7L), 0x1.0fae81914a991308p-1L);
|
|
nsz |
0c7d46 |
D(log2(0.7), -0x1.0776228967d13p-1);
|
|
nsz |
0c7d46 |
F(log2f(0.7f), -0x1.077624p-1);
|
|
nsz |
0c7d46 |
L(log2l(0.7L), -0x1.0776228967d1218cp-1L);
|
|
nsz |
0c7d46 |
D(logb(0.7), -0x1p+0);
|
|
nsz |
0c7d46 |
F(logbf(0.7f), -0x1p+0);
|
|
nsz |
0c7d46 |
L(logbl(0.7L), -0x1p+0L);
|
|
nsz |
0c7d46 |
IL(lrint(0.7), 1);
|
|
nsz |
0c7d46 |
IL(lrintf(0.7f), 1);
|
|
nsz |
0c7d46 |
IL(lrintl(0.7l), 1);
|
|
nsz |
0c7d46 |
IL(lround(0.7), 1);
|
|
nsz |
0c7d46 |
IL(lroundf(0.7f), 1);
|
|
nsz |
0c7d46 |
IL(lroundl(0.7L), 1);
|
|
nsz |
0c7d46 |
D(modf(0.7, &q), 0x1.6666666666666p-1);
|
|
nsz |
0c7d46 |
F(modff(0.7f, &qf), 0x1.666666p-1);
|
|
nsz |
0c7d46 |
L(modfl(0.7L, &ql), 0x1.6666666666666666p-1L);
|
|
nsz |
0c7d46 |
D(nearbyint(0.7), 0x1p+0);
|
|
nsz |
0c7d46 |
F(nearbyintf(0.7f), 0x1p+0);
|
|
nsz |
0c7d46 |
L(nearbyintl(0.7L), 0x1p+0L);
|
|
nsz |
0c7d46 |
D(nextafter(0.7, 1.0), 0x1.6666666666667p-1);
|
|
nsz |
0c7d46 |
F(nextafterf(0.7f, 1.0f), 0x1.666668p-1);
|
|
nsz |
0c7d46 |
L(nextafterl(0.7L, 1.0L), 0x1.6666666666666667p-1L);
|
|
nsz |
0c7d46 |
D(nexttoward(0.7, 1.0L), 0x1.6666666666667p-1);
|
|
nsz |
0c7d46 |
F(nexttowardf(0.7f, 1.0L), 0x1.666668p-1);
|
|
nsz |
0c7d46 |
L(nexttowardl(0.7L, 1.0L), 0x1.6666666666666667p-1L);
|
|
nsz |
0c7d46 |
D(pow(0.7, 1.5), 0x1.2bdbe460916ep-1);
|
|
nsz |
0c7d46 |
F(powf(0.7f, 1.5f), 0x1.2bdbe4p-1);
|
|
nsz |
0c7d46 |
L(powl(0.7L, 1.5L), 0x1.2bdbe460916e0b5p-1L);
|
|
nsz |
0c7d46 |
D(remainder(0.7, 0.5), 0x1.9999999999998p-3);
|
|
nsz |
0c7d46 |
F(remainderf(0.7f, 0.5f), 0x1.999998p-3);
|
|
nsz |
0c7d46 |
L(remainderl(0.7L, 0.5L), 0x1.9999999999999998p-3L);
|
|
nsz |
0c7d46 |
D(remquo(0.7, 0.5, &i), 0x1.9999999999998p-3);
|
|
nsz |
0c7d46 |
F(remquof(0.7f, 0.5f, &i), 0x1.999998p-3);
|
|
nsz |
0c7d46 |
L(remquol(0.7L, 0.5L, &i), 0x1.9999999999999998p-3L);
|
|
nsz |
0c7d46 |
D(rint(0.7), 0x1p+0);
|
|
nsz |
0c7d46 |
F(rintf(0.7f), 0x1p+0);
|
|
nsz |
0c7d46 |
L(rintl(0.7L), 0x1p+0L);
|
|
nsz |
0c7d46 |
D(round(0.7), 0x1p+0);
|
|
nsz |
0c7d46 |
F(roundf(0.7f), 0x1p+0);
|
|
nsz |
0c7d46 |
L(roundl(0.7L), 0x1p+0L);
|
|
nsz |
0c7d46 |
D(scalb(0.7, 3), 0x1.6666666666666p+2);
|
|
nsz |
0c7d46 |
F(scalbf(0.7f, 3), 0x1.666666p+2);
|
|
nsz |
0c7d46 |
D(scalbln(0.7, 3), 0x1.6666666666666p+2);
|
|
nsz |
0c7d46 |
F(scalblnf(0.7f, 3), 0x1.666666p+2);
|
|
nsz |
0c7d46 |
L(scalblnl(0.7L, 3), 0x1.6666666666666666p+2L);
|
|
nsz |
0c7d46 |
D(scalbn(0.7, 3), 0x1.6666666666666p+2);
|
|
nsz |
0c7d46 |
F(scalbnf(0.7f, 3), 0x1.666666p+2);
|
|
nsz |
0c7d46 |
L(scalbnl(0.7L, 3), 0x1.6666666666666666p+2L);
|
|
nsz |
0c7d46 |
D(sin(0.7), 0x1.49d6e694619b8p-1);
|
|
nsz |
0c7d46 |
F(sinf(0.7f), 0x1.49d6e6p-1);
|
|
nsz |
0c7d46 |
L(sinl(0.7L), 0x1.49d6e694619b854ep-1L);
|
|
nsz |
0c7d46 |
D(sinh(0.7), 0x1.8465153d5bdbdp-1);
|
|
nsz |
0c7d46 |
F(sinhf(0.7f), 0x1.846514p-1);
|
|
nsz |
0c7d46 |
L(sinhl(0.7L), 0x1.8465153d5bdbd0dep-1L);
|
|
nsz |
0c7d46 |
D(sqrt(0.7), 0x1.ac5eb3f7ab2f8p-1);
|
|
nsz |
0c7d46 |
F(sqrtf(0.7f), 0x1.ac5eb4p-1);
|
|
nsz |
0c7d46 |
L(sqrtl(0.7L), 0x1.ac5eb3f7ab2f7de2p-1L);
|
|
nsz |
0c7d46 |
D(tan(0.7), 0x1.af406c2fc78aep-1);
|
|
nsz |
0c7d46 |
F(tanf(0.7f), 0x1.af406cp-1);
|
|
nsz |
0c7d46 |
L(tanl(0.7L), 0x1.af406c2fc78ae54cp-1L);
|
|
nsz |
0c7d46 |
D(tanh(0.7), 0x1.356fb17af2e91p-1);
|
|
nsz |
0c7d46 |
F(tanhf(0.7f), 0x1.356fb2p-1);
|
|
nsz |
0c7d46 |
L(tanhl(0.7L), 0x1.356fb17af2e9100ap-1L);
|
|
nsz |
0c7d46 |
D(tgamma(0.7), 0x1.4c4d5ab21ea23p+0);
|
|
nsz |
0c7d46 |
F(tgammaf(0.7f), 0x1.4c4d5cp+0);
|
|
nsz |
0c7d46 |
L(tgammal(0.7L), 0x1.4c4d5ab21ea22798p+0L);
|
|
nsz |
0c7d46 |
D(trunc(0.7), 0x0p+0);
|
|
nsz |
0c7d46 |
F(truncf(0.7f), 0x0p+0);
|
|
nsz |
0c7d46 |
L(truncl(0.7L), 0x0p+0L);
|
|
nsz |
0c7d46 |
D(y0(0.7), -0x1.867b559ffc715p-3);
|
|
nsz |
0c7d46 |
F(y0f(0.7f), -0x1.867b58p-3);
|
|
nsz |
0c7d46 |
D(y1(0.7), -0x1.1a6e956728d35p+0);
|
|
nsz |
0c7d46 |
F(y1f(0.7f), -0x1.1a6e96p+0);
|
|
nsz |
0c7d46 |
D(yn(2, 0.7), -0x1.7b11b25df166ep+1);
|
|
nsz |
0c7d46 |
F(ynf(2, 0.7f), -0x1.7b11b4p+1);
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
return 0;
|
|
nsz |
0c7d46 |
}
|