diff --git a/src/math/frexp.c b/src/math/frexp.c new file mode 100644 index 0000000..19bc401 --- /dev/null +++ b/src/math/frexp.c @@ -0,0 +1,37 @@ +#include +#include +#include "util.h" + +static struct d_di t[] = { +#include "sanity/frexp.h" + +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct d_di *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = frexp(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s frexp(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s frexp(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/frexpf.c b/src/math/frexpf.c new file mode 100644 index 0000000..e4f05c1 --- /dev/null +++ b/src/math/frexpf.c @@ -0,0 +1,37 @@ +#include +#include +#include "util.h" + +static struct f_fi t[] = { +#include "sanity/frexpf.h" + +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct f_fi *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = frexpf(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s frexpf(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s frexpf(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/frexpl.c b/src/math/frexpl.c new file mode 100644 index 0000000..9d56bf2 --- /dev/null +++ b/src/math/frexpl.c @@ -0,0 +1,42 @@ +#include +#include +#include "util.h" + +static struct l_li t[] = { +#if LDBL_MANT_DIG == 53 +#include "sanity/frexp.h" + +#elif LDBL_MANT_DIG == 64 +#include "sanity/frexpl.h" + +#endif +}; + +int main(void) +{ + int yi; + long double y; + float d; + int e, i, err = 0; + struct l_li *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = frexpl(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s frexpl(%La)=%La,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s frexpl(%La) want %La,%lld got %La,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/gen/functions.h b/src/math/gen/functions.h index 104608e..b8e3180 100644 --- a/src/math/gen/functions.h +++ b/src/math/gen/functions.h @@ -132,20 +132,15 @@ T(y1, d_d) T(scalb, dd_d) T(scalbf, ff_f) T(j0f, f_f) -T(j0l, l_l) T(j1f, f_f) -T(j1l, l_l) T(y0f, f_f) -T(y0l, l_l) T(y1f, f_f) -T(y1l, l_l) T(exp10, d_d) T(exp10f, f_f) T(exp10l, l_l) T(pow10, d_d) T(pow10f, f_f) T(pow10l, l_l) - T(frexp, d_di) T(frexpf, f_fi) T(frexpl, l_li) diff --git a/src/math/gen/template/d_di.c b/src/math/gen/template/d_di.c new file mode 100644 index 0000000..3b224fa --- /dev/null +++ b/src/math/gen/template/d_di.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct d_di t[] = { +HEADERS +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct d_di *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ___(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ___(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s ___(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/gen/template/di_d.c b/src/math/gen/template/di_d.c new file mode 100644 index 0000000..43fa506 --- /dev/null +++ b/src/math/gen/template/di_d.c @@ -0,0 +1,35 @@ +#include +#include +#include "util.h" + +static struct di_d t[] = { +HEADERS +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct di_d *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ___(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ___(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ___(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/gen/template/f_fi.c b/src/math/gen/template/f_fi.c new file mode 100644 index 0000000..e697ca5 --- /dev/null +++ b/src/math/gen/template/f_fi.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct f_fi t[] = { +HEADERS +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct f_fi *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ___(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ___(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ___(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/gen/template/fi_f.c b/src/math/gen/template/fi_f.c new file mode 100644 index 0000000..b989822 --- /dev/null +++ b/src/math/gen/template/fi_f.c @@ -0,0 +1,35 @@ +#include +#include +#include "util.h" + +static struct fi_f t[] = { +HEADERS +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct fi_f *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ___(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ___(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ___(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/gen/template/l_li.c b/src/math/gen/template/l_li.c new file mode 100644 index 0000000..1bfa9de --- /dev/null +++ b/src/math/gen/template/l_li.c @@ -0,0 +1,40 @@ +#include +#include +#include "util.h" + +static struct l_li t[] = { +#if LDBL_MANT_DIG == 53 +DHEADERS +#elif LDBL_MANT_DIG == 64 +HEADERS +#endif +}; + +int main(void) +{ + int yi; + long double y; + float d; + int e, i, err = 0; + struct l_li *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ___(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ___(%La)=%La,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s ___(%La) want %La,%lld got %La,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/gen/template/li_l.c b/src/math/gen/template/li_l.c new file mode 100644 index 0000000..b11e461 --- /dev/null +++ b/src/math/gen/template/li_l.c @@ -0,0 +1,39 @@ +#include +#include +#include "util.h" + +static struct li_l t[] = { +#if LDBL_MANT_DIG == 53 +DHEADERS +#elif LDBL_MANT_DIG == 64 +HEADERS +#endif +}; + +int main(void) +{ + long double y; + float d; + int e, i, err = 0; + struct li_l *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ___(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ___(%La, %lld)=%La, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ___(%La, %lld) want %La got %La ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/ldexp.c b/src/math/ldexp.c new file mode 100644 index 0000000..7605945 --- /dev/null +++ b/src/math/ldexp.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct di_d t[] = { +#include "sanity/ldexp.h" + +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct di_d *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ldexp(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ldexp(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ldexp(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/ldexpf.c b/src/math/ldexpf.c new file mode 100644 index 0000000..dd0f8b8 --- /dev/null +++ b/src/math/ldexpf.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct fi_f t[] = { +#include "sanity/ldexpf.h" + +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct fi_f *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ldexpf(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ldexpf(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ldexpf(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/ldexpl.c b/src/math/ldexpl.c new file mode 100644 index 0000000..ddd867b --- /dev/null +++ b/src/math/ldexpl.c @@ -0,0 +1,41 @@ +#include +#include +#include "util.h" + +static struct li_l t[] = { +#if LDBL_MANT_DIG == 53 +#include "sanity/ldexp.h" + +#elif LDBL_MANT_DIG == 64 +#include "sanity/ldexpl.h" + +#endif +}; + +int main(void) +{ + long double y; + float d; + int e, i, err = 0; + struct li_l *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = ldexpl(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s ldexpl(%La, %lld)=%La, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s ldexpl(%La, %lld) want %La got %La ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/lgamma.c b/src/math/lgamma.c new file mode 100644 index 0000000..301a967 --- /dev/null +++ b/src/math/lgamma.c @@ -0,0 +1,38 @@ +#include +#include +#include "util.h" + +static struct d_di t[] = { +#include "sanity/lgamma.h" + +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct d_di *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = lgamma(p->x); + yi = signgam; + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s lgamma(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s lgamma(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/lgamma_r.c b/src/math/lgamma_r.c new file mode 100644 index 0000000..87ccada --- /dev/null +++ b/src/math/lgamma_r.c @@ -0,0 +1,37 @@ +#include +#include +#include "util.h" + +static struct d_di t[] = { +#include "sanity/lgamma_r.h" + +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct d_di *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = lgamma_r(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s lgamma_r(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s lgamma_r(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/lgammaf.c b/src/math/lgammaf.c new file mode 100644 index 0000000..0ac09fc --- /dev/null +++ b/src/math/lgammaf.c @@ -0,0 +1,38 @@ +#include +#include +#include "util.h" + +static struct f_fi t[] = { +#include "sanity/lgammaf.h" + +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct f_fi *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = lgammaf(p->x); + yi = signgam; + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s lgammaf(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s lgammaf(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/lgammaf_r.c b/src/math/lgammaf_r.c new file mode 100644 index 0000000..a81b644 --- /dev/null +++ b/src/math/lgammaf_r.c @@ -0,0 +1,37 @@ +#include +#include +#include "util.h" + +static struct f_fi t[] = { +#include "sanity/lgammaf_r.h" + +}; + +int main(void) +{ + int yi; + double y; + float d; + int e, i, err = 0; + struct f_fi *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = lgammaf_r(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s lgammaf_r(%a)=%a,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s lgammaf_r(%a) want %a,%lld got %a,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/lgammal.c b/src/math/lgammal.c new file mode 100644 index 0000000..ef25118 --- /dev/null +++ b/src/math/lgammal.c @@ -0,0 +1,43 @@ +#include +#include +#include "util.h" + +static struct l_li t[] = { +#if LDBL_MANT_DIG == 53 +#include "sanity/lgamma.h" + +#elif LDBL_MANT_DIG == 64 +#include "sanity/lgammal.h" + +#endif +}; + +int main(void) +{ + int yi; + long double y; + float d; + int e, i, err = 0; + struct l_li *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = lgammal(p->x); + yi = signgam; + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s lgammal(%La)=%La,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s lgammal(%La) want %La,%lld got %La,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/lgammal_r.c b/src/math/lgammal_r.c new file mode 100644 index 0000000..bfb8efc --- /dev/null +++ b/src/math/lgammal_r.c @@ -0,0 +1,42 @@ +#include +#include +#include "util.h" + +static struct l_li t[] = { +#if LDBL_MANT_DIG == 53 +#include "sanity/lgammal_r.h" + +#elif LDBL_MANT_DIG == 64 +#include "sanity/lgammal_r.h" + +#endif +}; + +int main(void) +{ + int yi; + long double y; + float d; + int e, i, err = 0; + struct l_li *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = lgammal_r(p->x, &yi); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s lgammal_r(%La)=%La,%lld, want %s", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r) || yi != p->i) { + printf("%s:%d: %s lgammal_r(%La) want %La,%lld got %La,%d ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->y, p->i, y, yi, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/scalbln.c b/src/math/scalbln.c new file mode 100644 index 0000000..a53dc39 --- /dev/null +++ b/src/math/scalbln.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct di_d t[] = { +#include "sanity/scalbln.h" + +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct di_d *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = scalbln(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s scalbln(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s scalbln(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/scalblnf.c b/src/math/scalblnf.c new file mode 100644 index 0000000..ccb7eec --- /dev/null +++ b/src/math/scalblnf.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct fi_f t[] = { +#include "sanity/scalblnf.h" + +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct fi_f *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = scalblnf(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s scalblnf(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s scalblnf(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/scalblnl.c b/src/math/scalblnl.c new file mode 100644 index 0000000..b06c407 --- /dev/null +++ b/src/math/scalblnl.c @@ -0,0 +1,41 @@ +#include +#include +#include "util.h" + +static struct li_l t[] = { +#if LDBL_MANT_DIG == 53 +#include "sanity/scalbln.h" + +#elif LDBL_MANT_DIG == 64 +#include "sanity/scalblnl.h" + +#endif +}; + +int main(void) +{ + long double y; + float d; + int e, i, err = 0; + struct li_l *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = scalblnl(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s scalblnl(%La, %lld)=%La, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s scalblnl(%La, %lld) want %La got %La ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/scalbn.c b/src/math/scalbn.c new file mode 100644 index 0000000..317d082 --- /dev/null +++ b/src/math/scalbn.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct di_d t[] = { +#include "sanity/scalbn.h" + +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct di_d *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = scalbn(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s scalbn(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperr(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s scalbn(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/scalbnf.c b/src/math/scalbnf.c new file mode 100644 index 0000000..5391264 --- /dev/null +++ b/src/math/scalbnf.c @@ -0,0 +1,36 @@ +#include +#include +#include "util.h" + +static struct fi_f t[] = { +#include "sanity/scalbnf.h" + +}; + +int main(void) +{ + double y; + float d; + int e, i, err = 0; + struct fi_f *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = scalbnf(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s scalbnf(%a, %lld)=%a, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrf(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s scalbnf(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/scalbnl.c b/src/math/scalbnl.c new file mode 100644 index 0000000..fe26540 --- /dev/null +++ b/src/math/scalbnl.c @@ -0,0 +1,41 @@ +#include +#include +#include "util.h" + +static struct li_l t[] = { +#if LDBL_MANT_DIG == 53 +#include "sanity/scalbn.h" + +#elif LDBL_MANT_DIG == 64 +#include "sanity/scalbnl.h" + +#endif +}; + +int main(void) +{ + long double y; + float d; + int e, i, err = 0; + struct li_l *p; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + p = t + i; + setupfenv(p->r); + y = scalbnl(p->x, p->i); + e = getexcept(); + if (!checkexcept(e, p->e, p->r)) { + printf("%s:%d: bad fp exception: %s scalbnl(%La, %lld)=%La, want %s", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e)); + printf(" got %s\n", estr(e)); + err++; + } + d = ulperrl(y, p->y, p->dy); + if (!checkulp(d, p->r)) { + printf("%s:%d: %s scalbnl(%La, %lld) want %La got %La ulperr %.3f = %a + %a\n", + p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy); + err++; + } + } + return !!err; +} diff --git a/src/math/test.h b/src/math/test.h deleted file mode 100644 index e69de29..0000000 --- a/src/math/test.h +++ /dev/null diff --git a/src/math/util.h b/src/math/util.h index 62630a8..10d9279 100644 --- a/src/math/util.h +++ b/src/math/util.h @@ -6,21 +6,57 @@ #undef RZ #undef RD #undef RU +#ifdef FE_TONEAREST #define RN FE_TONEAREST +#else +#define RN 0 +#endif +#ifdef FE_TOWARDZERO #define RZ FE_TOWARDZERO +#else +#define RZ -1 +#endif +#ifdef FE_DOWNWARD #define RD FE_DOWNWARD +#else +#define RD -1 +#endif +#ifdef FE_UPWARD #define RU FE_UPWARD +#else +#define RU -1 +#endif #undef INEXACT #undef INVALID #undef DIVBYZERO #undef UNDERFLOW #undef OVERFLOW +#ifdef FE_INEXACT #define INEXACT FE_INEXACT +#else +#define INEXACT 0 +#endif +#ifdef FE_INVALID #define INVALID FE_INVALID +#else +#define INVALID 0 +#endif +#ifdef FE_DIVBYZERO #define DIVBYZERO FE_DIVBYZERO +#else +#define DIVBYZERO 0 +#endif +#ifdef FE_UNDERFLOW #define UNDERFLOW FE_UNDERFLOW +#else +#define UNDERFLOW 0 +#endif +#ifdef FE_OVERFLOW #define OVERFLOW FE_OVERFLOW +#else +#define OVERFLOW 0 +#endif #undef inf #undef nan @@ -36,6 +72,13 @@ struct l_l {POS int r; long double x; long double y; float dy; int e; }; struct ff_f {POS int r; float x; float x2; float y; float dy; int e; }; struct dd_d {POS int r; double x; double x2; double y; float dy; int e; }; struct ll_l {POS int r; long double x; long double x2; long double y; float dy; int e; }; +struct d_di {POS int r; double x; double y; float dy; long long i; int e; }; +struct f_fi {POS int r; float x; float y; float dy; long long i; int e; }; +struct l_li {POS int r; long double x; long double y; float dy; long long i; int e; }; +struct di_d {POS int r; double x; long long i; double y; float dy; int e; }; +struct fi_f {POS int r; float x; long long i; float y; float dy; int e; }; +struct li_l {POS int r; long double x; long long i; long double y; float dy; int e; }; +#undef POS char *estr(int); char *rstr(int);