1 From 6c4538905e65ceb203f59aaa9a61728e81c6bc0a Mon Sep 17 00:00:00 2001
2 From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
3 Date: Wed, 18 Mar 2015 21:32:22 +0000
4 Subject: libm: Add missing C99 float/ld wrappers
6 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
8 Status: upstream [uClibc]
9 http://git.uclibc.org/uClibc/commit/?id=6c4538905e65ceb203f59aaa9a61728e81c6bc0a
11 Removed patch for ./TODO.
12 Needed to avoid run-time errors with mesa3d which depends on fminf
14 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
16 diff --git a/include/complex.h b/include/complex.h
17 index 91efc0d..ed7e502 100644
18 --- a/include/complex.h
19 +++ b/include/complex.h
20 @@ -79,6 +79,7 @@ __BEGIN_DECLS
22 #include <bits/cmathcalls.h>
25 #undef __MATH_PRECNAME
27 /* And the long double versions. It is non-critical to define them
28 @@ -97,6 +98,7 @@ __BEGIN_DECLS
29 # include <bits/cmathcalls.h>
32 +#undef _Mlong_double_
33 #undef __MATH_PRECNAME
36 diff --git a/include/math.h b/include/math.h
37 index ecb9aa6..1b54c9e 100644
40 @@ -129,6 +129,7 @@ __BEGIN_DECLS
42 # undef _Mdouble_BEGIN_NAMESPACE
43 # undef _Mdouble_END_NAMESPACE
45 # undef __MATH_PRECNAME
46 # undef __MATH_maybe_libm_hidden_proto
48 @@ -176,6 +177,7 @@ extern long double __REDIRECT_NTH (nexttowardl, (long double __x, long double __
50 # undef _Mdouble_BEGIN_NAMESPACE
51 # undef _Mdouble_END_NAMESPACE
52 +# undef _Mlong_double_
53 # undef __MATH_PRECNAME
54 # undef __MATH_maybe_libm_hidden_proto
56 diff --git a/libc/sysdeps/linux/common/bits/mathcalls.h b/libc/sysdeps/linux/common/bits/mathcalls.h
57 index 84b793c..9bebb51 100644
58 --- a/libc/sysdeps/linux/common/bits/mathcalls.h
59 +++ b/libc/sysdeps/linux/common/bits/mathcalls.h
60 @@ -74,8 +74,22 @@ __MATHCALLI (atan2,, (_Mdouble_ __y, _Mdouble_ __x))
63 __MATHCALLI (cos,, (_Mdouble_ __x))
64 +# if defined _LIBC && defined _Mlong_double_
65 +libm_hidden_proto(cosl)
67 +# if defined _LIBC && defined _Mfloat_
68 +libm_hidden_proto(cosf)
72 __MATHCALLI (sin,, (_Mdouble_ __x))
73 +# if defined _LIBC && defined _Mlong_double_
74 +libm_hidden_proto(sinl)
76 +# if defined _LIBC && defined _Mfloat_
77 +libm_hidden_proto(sinf)
81 __MATHCALLI (tan,, (_Mdouble_ __x))
83 @@ -111,6 +125,9 @@ __END_NAMESPACE_C99
84 _Mdouble_BEGIN_NAMESPACE
85 /* Exponential function of X. */
86 __MATHCALLI (exp,, (_Mdouble_ __x))
87 +# if defined _LIBC && defined _Mlong_double_
88 +libm_hidden_proto(expl)
91 /* Break VALUE into a normalized fraction and an integral power of 2. */
92 __MATHCALLI (frexp,, (_Mdouble_ __x, int *__exponent))
93 @@ -173,6 +190,9 @@ _Mdouble_END_NAMESPACE
95 /* Return `sqrt(X*X + Y*Y)'. */
96 __MATHCALLI (hypot,, (_Mdouble_ __x, _Mdouble_ __y))
97 +# if defined _LIBC && defined _Mlong_double_
98 +libm_hidden_proto(hypotl)
103 @@ -298,6 +318,9 @@ __MATHCALLI (rint,, (_Mdouble_ __x))
105 /* Return X + epsilon if X < Y, X - epsilon if X > Y. */
106 __MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__))
107 +# if defined _LIBC && defined _Mlong_double_
108 +libm_hidden_proto(nextafterl)
110 # if defined __USE_ISOC99 && !defined __LDBL_COMPAT
111 __MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__))
113 diff --git a/libm/Makefile.in b/libm/Makefile.in
114 index 7511706..d886cdb 100644
115 --- a/libm/Makefile.in
116 +++ b/libm/Makefile.in
117 @@ -75,9 +75,6 @@ libm_CSRC := \
118 s_remquo.c w_exp2.c \
121 -# Not implemented [yet?], see comment in float_wrappers.c:
122 -# fdimf.o fmaf.o fmaxf.o fminf.o
123 -# nearbyintf.o remquof.o scalblnf.o tgammaf.o
127 @@ -98,7 +95,11 @@ FL_MOBJ := \
139 @@ -116,11 +117,14 @@ FL_MOBJ := \
155 @@ -128,9 +132,24 @@ FL_MOBJ := \
162 -# Not implemented [yet?]: nexttowardl.o
163 +ifeq ($(UCLIBC_SUSV3_LEGACY),y)
167 +# Do not (yet?) implement the float variants of bessel functions
168 +ifeq (not-yet-implemented-$(DO_XSI_MATH),y)
181 @@ -180,6 +199,7 @@ LD_MOBJ := \
189 @@ -196,6 +216,17 @@ LD_MOBJ := \
193 +# Do not (yet?) implement the long double variants of bessel functions
194 +ifeq (not-yet-implemented-$(DO_XSI_MATH),y)
206 # This list of math functions was taken from POSIX/IEEE 1003.1b-1993
207 diff --git a/libm/float_wrappers.c b/libm/float_wrappers.c
208 index 82b7963..105486e 100644
209 --- a/libm/float_wrappers.c
210 +++ b/libm/float_wrappers.c
211 @@ -38,19 +38,14 @@ long long func##f (float x) \
212 return func((double)x); \
216 -/* For the time being, do _NOT_ implement these functions
217 - * that are defined by SuSv3 [because we don't need them
218 - * and nobody asked to include them] */
219 -#undef L_fdimf /*float fdimf(float, float);*/
220 -#undef L_fmaf /*float fmaf(float, float, float);*/
221 -#undef L_fmaxf /*float fmaxf(float, float);*/
222 -#undef L_fminf /*float fminf(float, float);*/
223 -#undef L_nearbyintf /*float nearbyintf(float);*/
224 -#undef L_nexttowardf /*float nexttowardf(float, long double);*/
225 -#undef L_remquof /*float remquof(float, float, int *);*/
226 -#undef L_scalblnf /*float scalblnf(float, long);*/
227 -#undef L_tgammaf /*float tgammaf(float);*/
228 +#ifndef __DO_XSI_MATH__
229 +# undef L_j0f /* float j0f(float x); */
230 +# undef L_j1f /* float j1f(float x); */
231 +# undef L_jnf /* float jnf(int n, float x); */
232 +# undef L_y0f /* float y0f(float x); */
233 +# undef L_y1f /* float y1f(float x); */
234 +# undef L_ynf /* float ynf(int n, float x); */
237 /* Implement the following, as defined by SuSv3 */
239 @@ -155,6 +150,7 @@ float copysignf (float x, float y)
243 +libm_hidden_def(cosf)
247 @@ -242,6 +238,21 @@ float hypotf (float x, float y)
260 +float jnf(int n, float x)
262 + return (float) jn(n, (double)x);
267 float ldexpf (float x, int _exp)
269 @@ -306,7 +317,7 @@ WRAPPER1(nearbyint)
271 float nexttowardf (float x, long double y)
273 - return (float) nexttoward( (double)x, (double)y );
274 + return (float) nexttoward( (double)x, (long double)y );
278 @@ -355,6 +366,7 @@ float scalbnf (float x, int _exp)
282 +libm_hidden_def(sinf)
286 @@ -381,13 +393,6 @@ WRAPPER1(tgamma)
291 -float fmaf (float x, float y, float z)
293 - return (float) fma( (double)x, (double)y, (double)z );
297 #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__
298 float scalbf (float x, float y)
300 @@ -402,3 +407,18 @@ WRAPPER1(gamma)
301 #ifdef L_significandf
302 WRAPPER1(significand)
314 +float ynf(int n, float x)
316 + return (float) yn(n, (double)x);
319 diff --git a/libm/ldouble_wrappers.c b/libm/ldouble_wrappers.c
320 index 118a78f..b4215cb 100644
321 --- a/libm/ldouble_wrappers.c
322 +++ b/libm/ldouble_wrappers.c
323 @@ -42,6 +42,15 @@ long long func##l(long double x) \
324 return func((double) x); \
327 +#ifndef __DO_XSI_MATH__
328 +# undef L_j0l /* long double j0l(long double x); */
329 +# undef L_j1l /* long double j1l(long double x); */
330 +# undef L_jnl /* long double jnl(int n, long double x); */
331 +# undef L_y0l /* long double y0l(long double x); */
332 +# undef L_y1l /* long double y1l(long double x); */
333 +# undef L_ynl /* long double ynl(int n, long double x); */
336 /* Implement the following, as defined by SuSv3 */
338 long double acoshl(long double);
339 @@ -156,6 +165,7 @@ WRAPPER1(cosh)
343 +libm_hidden_def(cosl)
347 @@ -172,6 +182,7 @@ WRAPPER1(exp2)
351 +libm_hidden_def(expl)
355 @@ -222,12 +233,28 @@ WRAPPER1(gamma)
359 +libm_hidden_def(hypotl)
375 +long double jnl(int n, long double x)
377 + return (long double) jn(n, (double)x);
382 long double ldexpl (long double x, int ex)
384 @@ -291,12 +318,18 @@ WRAPPER1(nearbyint)
388 +libm_hidden_def(nextafterl)
391 -/* Disabled in Makefile.in */
392 -#if 0 /* def L_nexttowardl */
393 -WRAPPER2(nexttoward)
394 -libm_hidden_def(nexttowardl)
395 +#ifdef L_nexttowardl
397 +strong_alias(nextafterl, nexttowardl)
399 +long double nexttowardl(long double x, long double y)
401 + return nextafterl(x, y);
407 @@ -344,6 +377,7 @@ WRAPPER1(sinh)
411 +libm_hidden_def(sinl)
415 @@ -370,6 +404,22 @@ WRAPPER1(trunc)
416 WRAPPER1(significand)
428 +long double ynl(int n, long double x)
430 + return (long double) yn(n, (double)x);
435 #if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH
437 # ifdef L___fpclassifyl
438 diff --git a/libm/s_fdim.c b/libm/s_fdim.c
439 index 6249219..6ed695c 100644
445 #include "math_private.h"
448 double fdim(double x, double y)
450 - int c = __fpclassify(x);
451 - if (c == FP_NAN || c == FP_INFINITE)
453 + int cx = __fpclassify(x); /* need both NAN and INF */
454 + int cy = __fpclassify(y); /* need both NAN and INF */
455 + if (cx == FP_NAN || cy == NAN)
458 - return x > y ? x - y : 0.0;
463 + if (isinf(z) && cx != FP_INFINITE && cy != FP_INFINITE)
464 + __set_errno(ERANGE);
468 libm_hidden_def(fdim)
469 diff --git a/libm/s_fmax.c b/libm/s_fmax.c
470 index 21dfaa9..5f29ad8 100644
475 double fmax(double x, double y)
477 - if (__fpclassify(x) == FP_NAN)
479 - if (__fpclassify(y) == FP_NAN)
485 return x > y ? x : y;
487 diff --git a/libm/s_fmin.c b/libm/s_fmin.c
488 index 674d9a5..a549678 100644
493 double fmin(double x, double y)
495 - if (__fpclassify(x) == FP_NAN)
497 - if (__fpclassify(y) == FP_NAN)
503 return x < y ? x : y;
505 diff --git a/libm/s_nextafter.c b/libm/s_nextafter.c
506 index ee4621c..73a8ab2 100644
507 --- a/libm/s_nextafter.c
508 +++ b/libm/s_nextafter.c
509 @@ -32,7 +32,7 @@ double nextafter(double x, double y)
510 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
511 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
513 - if(x==y) return x; /* x=y, return x */
514 + if(x==y) return y; /* x=y, return y */
515 if((ix|lx)==0) { /* x == 0 */
516 INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
518 @@ -68,3 +68,5 @@ double nextafter(double x, double y)
521 libm_hidden_def(nextafter)
522 +strong_alias_untyped(nextafter, nexttoward)
523 +libm_hidden_def(nexttoward)
524 diff --git a/test/math/compile_test.c b/test/math/compile_test.c
525 index ab8c40c..aedfde6 100644
526 --- a/test/math/compile_test.c
527 +++ b/test/math/compile_test.c
528 @@ -22,11 +22,11 @@ r += exp2f(float_x);
530 r += expm1f(float_x);
532 -/*r += fdimf(float_x, float_x); - uclibc does not have it (yet?) */
533 +r += fdimf(float_x, float_x);
534 r += floorf(float_x);
535 -/*r += fmaf(float_x, float_x, float_x); - uclibc does not have it (yet?) */
536 -/*r += fmaxf(float_x, float_x); - uclibc does not have it (yet?) */
537 -/*r += fminf(float_x, float_x); - uclibc does not have it (yet?) */
538 +r += fmaf(float_x, float_x, float_x);
539 +r += fmaxf(float_x, float_x);
540 +r += fminf(float_x, float_x);
541 r += fmodf(float_x, float_x);
542 r += frexpf(float_x, &int_x);
543 r += gammaf(float_x);
544 @@ -44,17 +44,17 @@ r += logf(float_x);
545 r += lrintf(float_x);
546 r += lroundf(float_x);
547 r += modff(float_x, &float_x);
548 -/*r += nearbyintf(float_x); - uclibc does not have it (yet?) */
549 -/*r += nexttowardf(float_x, long_double_x); - uclibc does not have it (yet?) */
550 +r += nearbyintf(float_x);
551 +r += nexttowardf(float_x, long_double_x);
552 r += powf(float_x, float_x);
553 r += remainderf(float_x, float_x);
554 -/*r += remquof(float_x, float_x, &int_x); - uclibc does not have it (yet?) */
555 +r += remquof(float_x, float_x, &int_x);
557 r += roundf(float_x);
558 #ifdef __UCLIBC_SUSV3_LEGACY__
559 r += scalbf(float_x, float_x);
561 -/*r += scalblnf(float_x, long_x); - uclibc does not have it (yet?) */
562 +r += scalblnf(float_x, long_x);
563 r += scalbnf(float_x, int_x);
564 r += significandf(float_x);
566 @@ -62,7 +62,7 @@ r += sinhf(float_x);
570 -/*r += tgammaf(float_x); - uclibc does not have it (yet?) */
571 +r += tgammaf(float_x);
572 r += truncf(float_x);
575 @@ -116,7 +116,7 @@ r += lroundl(long_double_x);
576 r += modfl(long_double_x, &long_double_x);
577 r += nearbyintl(long_double_x);
578 r += nextafterl(long_double_x, long_double_x);
579 -/* r += nexttowardl(long_double_x, long_double_x); - uclibc doesn't provide this [yet?] */
580 +r += nexttowardl(long_double_x, long_double_x);
581 r += powl(long_double_x, long_double_x);
582 r += remainderl(long_double_x, long_double_x);
583 r += remquol(long_double_x, long_double_x, &int_x);
584 diff --git a/test/math/libm-test.inc b/test/math/libm-test.inc
585 index d0f0a0c..8f0db3c 100644
586 --- a/test/math/libm-test.inc
587 +++ b/test/math/libm-test.inc
592 +#undef __CHK_COMPLEX_STUFF
593 +#define __CHK_COMPLEX_STUFF 0
595 #include "libm-test-ulps.h"
598 @@ -1120,8 +1123,10 @@ cacosh_test (void)
600 END (cacosh, complex);
605 +#if __CHK_COMPLEX_STUFF
609 @@ -1188,7 +1193,9 @@ carg_test (void)
613 +#endif /* __CHK_COMPLEX_STUFF */
619 @@ -1683,7 +1690,7 @@ ceil_test (void)
624 +#if __CHK_COMPLEX_STUFF
628 @@ -1746,8 +1753,9 @@ cexp_test (void)
632 +#endif /* __CHK_COMPLEX_STUFF */
639 @@ -2588,7 +2596,6 @@ fabs_test (void)
647 @@ -2624,7 +2631,6 @@ fdim_test (void)
655 @@ -2694,7 +2700,6 @@ floor_test (void)
663 @@ -2797,7 +2802,6 @@ fmin_test (void)
671 @@ -3002,7 +3006,7 @@ isnormal_test (void)
675 -#if defined __DO_XSI_MATH__
676 +#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT)
680 @@ -3629,7 +3633,6 @@ modf_test (void)
686 nearbyint_test (void)
688 @@ -3710,7 +3713,6 @@ nexttoward_test (void)
696 @@ -3950,7 +3952,6 @@ remainder_test (void)
704 @@ -3981,7 +3982,6 @@ remquo_test (void)
712 @@ -4229,12 +4229,12 @@ round_test (void)
716 +#ifdef __UCLIBC_SUSV3_LEGACY__
721 #ifndef TEST_LDOUBLE /* uclibc doesn't have scalbl */
722 -#ifdef __UCLIBC_SUSV3_LEGACY__ /* scalbf is susv3 legacy */
724 TEST_ff_f (scalb, 2.0, 0.5, nan_value, INVALID_EXCEPTION);
725 TEST_ff_f (scalb, 3.0, -2.5, nan_value, INVALID_EXCEPTION);
726 @@ -4285,11 +4285,10 @@ scalb_test (void)
728 TEST_ff_f (scalb, 0.8L, 4, 12.8L);
729 TEST_ff_f (scalb, -0.854375L, 5, -27.34L);
730 -#endif /* __UCLIBC_SUSV3_LEGACY__ */
731 #endif /* TEST_LDOUBLE */
739 @@ -4313,7 +4312,6 @@ scalbn_test (void)
747 @@ -4334,7 +4332,6 @@ scalbln_test (void)
755 @@ -4539,7 +4536,6 @@ tanh_test (void)
763 @@ -4571,7 +4567,6 @@ tgamma_test (void)
771 @@ -4651,7 +4646,7 @@ trunc_test (void)
775 -#if defined __DO_XSI_MATH__
776 +#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT)
780 @@ -4979,11 +4974,11 @@ main (int argc, char **argv)
784 +#ifdef __UCLIBC_SUSV3_LEGACY__
793 /* Power and absolute value functions: */
794 @@ -4998,16 +4993,12 @@ main (int argc, char **argv)
802 /* Nearest integer functions: */
810 rint_test_tonearest ();
811 @@ -5025,13 +5016,10 @@ main (int argc, char **argv)
812 /* Remainder functions: */
819 /* Manipulation functions: */
825 @@ -5043,24 +5031,29 @@ main (int argc, char **argv)
826 /* Multiply and add: */
830 /* Complex functions: */
832 +#if __CHK_COMPLEX_STUFF
857 @@ -5070,9 +5063,10 @@ main (int argc, char **argv)
861 +#endif /* __CHK_COMPLEX_STUFF */
863 /* Bessel functions: */
864 -#if defined __DO_XSI_MATH__
865 +#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT)