From 6c4538905e65ceb203f59aaa9a61728e81c6bc0a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:32:22 +0100 Subject: libm: Add missing C99 float/ld wrappers Signed-off-by: Bernhard Reutner-Fischer --- libm/Makefile.in | 41 ++++++++++++++++++++++++++++---- libm/float_wrappers.c | 62 ++++++++++++++++++++++++++++++++----------------- libm/ldouble_wrappers.c | 58 +++++++++++++++++++++++++++++++++++++++++---- libm/s_fdim.c | 17 ++++++++++---- libm/s_fmax.c | 6 ++--- libm/s_fmin.c | 6 ++--- libm/s_nextafter.c | 4 +++- 7 files changed, 153 insertions(+), 41 deletions(-) (limited to 'libm') diff --git a/libm/Makefile.in b/libm/Makefile.in index 751170678..d886cdbc5 100644 --- a/libm/Makefile.in +++ b/libm/Makefile.in @@ -75,9 +75,6 @@ libm_CSRC := \ s_remquo.c w_exp2.c \ cexp.c sincos.c -# Not implemented [yet?], see comment in float_wrappers.c: -# fdimf.o fmaf.o fmaxf.o fminf.o -# nearbyintf.o remquof.o scalblnf.o tgammaf.o FL_MOBJ := \ acosf.o \ acoshf.o \ @@ -98,7 +95,11 @@ FL_MOBJ := \ expf.o \ expm1f.o \ fabsf.o \ + fdimf.o \ floorf.o \ + fmaf.o \ + fmaxf.o \ + fminf.o \ fmodf.o \ frexpf.o \ gammaf.o \ @@ -116,11 +117,14 @@ FL_MOBJ := \ lrintf.o \ lroundf.o \ modff.o \ + nearbyintf.o \ + nexttowardf.o \ powf.o \ remainderf.o \ + remquof.o \ rintf.o \ roundf.o \ - scalbf.o \ + scalblnf.o \ scalbnf.o \ significandf.o \ sinf.o \ @@ -128,9 +132,24 @@ FL_MOBJ := \ sqrtf.o \ tanf.o \ tanhf.o \ + tgammaf.o \ truncf.o \ -# Not implemented [yet?]: nexttowardl.o +ifeq ($(UCLIBC_SUSV3_LEGACY),y) +FL_MOBJ += scalbf.o +endif + +# Do not (yet?) implement the float variants of bessel functions +ifeq (not-yet-implemented-$(DO_XSI_MATH),y) +FL_MOBJ += \ + j0f.o \ + j1f.o \ + jnf.o \ + y0f.o \ + y1f.o \ + ynf.o +endif + LD_MOBJ := \ __finitel.o \ __fpclassifyl.o \ @@ -180,6 +199,7 @@ LD_MOBJ := \ modfl.o \ nearbyintl.o \ nextafterl.o \ + nexttowardl.o \ powl.o \ remainderl.o \ remquol.o \ @@ -196,6 +216,17 @@ LD_MOBJ := \ tgammal.o \ truncl.o \ +# Do not (yet?) implement the long double variants of bessel functions +ifeq (not-yet-implemented-$(DO_XSI_MATH),y) +LD_MOBJ += \ + j0l.o \ + j1l.o \ + jnl.o \ + y0l.o \ + y1l.o \ + ynl.o +endif + else # This list of math functions was taken from POSIX/IEEE 1003.1b-1993 diff --git a/libm/float_wrappers.c b/libm/float_wrappers.c index 82b7963e1..105486e46 100644 --- a/libm/float_wrappers.c +++ b/libm/float_wrappers.c @@ -38,19 +38,14 @@ long long func##f (float x) \ return func((double)x); \ } - -/* For the time being, do _NOT_ implement these functions - * that are defined by SuSv3 [because we don't need them - * and nobody asked to include them] */ -#undef L_fdimf /*float fdimf(float, float);*/ -#undef L_fmaf /*float fmaf(float, float, float);*/ -#undef L_fmaxf /*float fmaxf(float, float);*/ -#undef L_fminf /*float fminf(float, float);*/ -#undef L_nearbyintf /*float nearbyintf(float);*/ -#undef L_nexttowardf /*float nexttowardf(float, long double);*/ -#undef L_remquof /*float remquof(float, float, int *);*/ -#undef L_scalblnf /*float scalblnf(float, long);*/ -#undef L_tgammaf /*float tgammaf(float);*/ +#ifndef __DO_XSI_MATH__ +# undef L_j0f /* float j0f(float x); */ +# undef L_j1f /* float j1f(float x); */ +# undef L_jnf /* float jnf(int n, float x); */ +# undef L_y0f /* float y0f(float x); */ +# undef L_y1f /* float y1f(float x); */ +# undef L_ynf /* float ynf(int n, float x); */ +#endif /* Implement the following, as defined by SuSv3 */ #if 0 @@ -155,6 +150,7 @@ float copysignf (float x, float y) #ifdef L_cosf WRAPPER1(cos) +libm_hidden_def(cosf) #endif #ifdef L_coshf @@ -242,6 +238,21 @@ float hypotf (float x, float y) int_WRAPPER1(ilogb) #endif +#ifdef L_j0f +WRAPPER1(j0) +#endif + +#ifdef L_j1f +WRAPPER1(j1) +#endif + +#ifdef L_jnf +float jnf(int n, float x) +{ + return (float) jn(n, (double)x); +} +#endif + #ifdef L_ldexpf float ldexpf (float x, int _exp) { @@ -306,7 +317,7 @@ WRAPPER1(nearbyint) #ifdef L_nexttowardf float nexttowardf (float x, long double y) { - return (float) nexttoward( (double)x, (double)y ); + return (float) nexttoward( (double)x, (long double)y ); } #endif @@ -355,6 +366,7 @@ float scalbnf (float x, int _exp) #ifdef L_sinf WRAPPER1(sin) +libm_hidden_def(sinf) #endif #ifdef L_sinhf @@ -381,13 +393,6 @@ WRAPPER1(tgamma) WRAPPER1(trunc) #endif -#ifdef L_fmaf -float fmaf (float x, float y, float z) -{ - return (float) fma( (double)x, (double)y, (double)z ); -} -#endif - #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__ float scalbf (float x, float y) { @@ -402,3 +407,18 @@ WRAPPER1(gamma) #ifdef L_significandf WRAPPER1(significand) #endif + +#ifdef L_y0f +WRAPPER1(y0) +#endif + +#ifdef L_y1f +WRAPPER1(y1) +#endif + +#ifdef L_ynf +float ynf(int n, float x) +{ + return (float) yn(n, (double)x); +} +#endif diff --git a/libm/ldouble_wrappers.c b/libm/ldouble_wrappers.c index 118a78f64..b4215cbf3 100644 --- a/libm/ldouble_wrappers.c +++ b/libm/ldouble_wrappers.c @@ -42,6 +42,15 @@ long long func##l(long double x) \ return func((double) x); \ } +#ifndef __DO_XSI_MATH__ +# undef L_j0l /* long double j0l(long double x); */ +# undef L_j1l /* long double j1l(long double x); */ +# undef L_jnl /* long double jnl(int n, long double x); */ +# undef L_y0l /* long double y0l(long double x); */ +# undef L_y1l /* long double y1l(long double x); */ +# undef L_ynl /* long double ynl(int n, long double x); */ +#endif + /* Implement the following, as defined by SuSv3 */ #if 0 long double acoshl(long double); @@ -156,6 +165,7 @@ WRAPPER1(cosh) #ifdef L_cosl WRAPPER1(cos) +libm_hidden_def(cosl) #endif #ifdef L_erfcl @@ -172,6 +182,7 @@ WRAPPER1(exp2) #ifdef L_expl WRAPPER1(exp) +libm_hidden_def(expl) #endif #ifdef L_expm1l @@ -222,12 +233,28 @@ WRAPPER1(gamma) #ifdef L_hypotl WRAPPER2(hypot) +libm_hidden_def(hypotl) #endif #ifdef L_ilogbl int_WRAPPER1(ilogb) #endif +#ifdef L_j0l + WRAPPER1(j0) +#endif + +#ifdef L_j1l + WRAPPER1(j1) +#endif + +#ifdef L_jnl +long double jnl(int n, long double x) +{ + return (long double) jn(n, (double)x); +} +#endif + #ifdef L_ldexpl long double ldexpl (long double x, int ex) { @@ -291,12 +318,18 @@ WRAPPER1(nearbyint) #ifdef L_nextafterl WRAPPER2(nextafter) +libm_hidden_def(nextafterl) #endif -/* Disabled in Makefile.in */ -#if 0 /* def L_nexttowardl */ -WRAPPER2(nexttoward) -libm_hidden_def(nexttowardl) +#ifdef L_nexttowardl +# if 0 /* TODO */ +strong_alias(nextafterl, nexttowardl) +# else +long double nexttowardl(long double x, long double y) +{ + return nextafterl(x, y); +} +#endif #endif #ifdef L_powl @@ -344,6 +377,7 @@ WRAPPER1(sinh) #ifdef L_sinl WRAPPER1(sin) +libm_hidden_def(sinl) #endif #ifdef L_sqrtl @@ -370,6 +404,22 @@ WRAPPER1(trunc) WRAPPER1(significand) #endif +#ifdef L_y0l +WRAPPER1(y0) +#endif + +#ifdef L_y1l +WRAPPER1(y1) +#endif + +#ifdef L_ynl +long double ynl(int n, long double x) +{ + return (long double) yn(n, (double)x); +} +#endif + + #if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH # ifdef L___fpclassifyl diff --git a/libm/s_fdim.c b/libm/s_fdim.c index 6249219c8..6ed695c3d 100644 --- a/libm/s_fdim.c +++ b/libm/s_fdim.c @@ -6,13 +6,22 @@ #include "math.h" #include "math_private.h" +#include double fdim(double x, double y) { - int c = __fpclassify(x); - if (c == FP_NAN || c == FP_INFINITE) - return HUGE_VAL; + int cx = __fpclassify(x); /* need both NAN and INF */ + int cy = __fpclassify(y); /* need both NAN and INF */ + if (cx == FP_NAN || cy == NAN) + return x - y; - return x > y ? x - y : 0.0; + if (x <= y) + return .0; + + double z = x - y; + if (isinf(z) && cx != FP_INFINITE && cy != FP_INFINITE) + __set_errno(ERANGE); + + return z; } libm_hidden_def(fdim) diff --git a/libm/s_fmax.c b/libm/s_fmax.c index 21dfaa981..5f29ad8e3 100644 --- a/libm/s_fmax.c +++ b/libm/s_fmax.c @@ -9,10 +9,10 @@ double fmax(double x, double y) { - if (__fpclassify(x) == FP_NAN) - return x; - if (__fpclassify(y) == FP_NAN) + if (isnan(x)) return y; + if (isnan(y)) + return x; return x > y ? x : y; } diff --git a/libm/s_fmin.c b/libm/s_fmin.c index 674d9a56b..a549678ee 100644 --- a/libm/s_fmin.c +++ b/libm/s_fmin.c @@ -9,10 +9,10 @@ double fmin(double x, double y) { - if (__fpclassify(x) == FP_NAN) - return x; - if (__fpclassify(y) == FP_NAN) + if (isnan(x)) return y; + if (isnan(y)) + return x; return x < y ? x : y; } diff --git a/libm/s_nextafter.c b/libm/s_nextafter.c index ee4621cc7..73a8ab2be 100644 --- a/libm/s_nextafter.c +++ b/libm/s_nextafter.c @@ -32,7 +32,7 @@ double nextafter(double x, double y) if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ return x+y; - if(x==y) return x; /* x=y, return x */ + if(x==y) return y; /* x=y, return y */ if((ix|lx)==0) { /* x == 0 */ INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ y = x*x; @@ -68,3 +68,5 @@ double nextafter(double x, double y) return x; } libm_hidden_def(nextafter) +strong_alias_untyped(nextafter, nexttoward) +libm_hidden_def(nexttoward) -- cgit v1.2.3