diff options
Diffstat (limited to 'math')
-rw-r--r-- | math/Makefile | 4 | ||||
-rw-r--r-- | math/Versions | 1 | ||||
-rw-r--r-- | math/bits/mathcalls.h | 5 | ||||
-rw-r--r-- | math/libm-test.inc | 45 | ||||
-rw-r--r-- | math/math.h | 21 | ||||
-rw-r--r-- | math/test-fp-llogb-constants.c | 48 | ||||
-rw-r--r-- | math/test-tgmath-ret.c | 2 | ||||
-rw-r--r-- | math/test-tgmath.c | 12 | ||||
-rw-r--r-- | math/tgmath.h | 3 | ||||
-rw-r--r-- | math/w_llogb_template.c | 46 |
10 files changed, 182 insertions, 5 deletions
diff --git a/math/Makefile b/math/Makefile index ac3a90a582..848b093863 100644 --- a/math/Makefile +++ b/math/Makefile @@ -52,7 +52,7 @@ gen-libm-calls = cargF conjF cimagF crealF cabsF s_cacosF \ k_casinhF s_csinhF k_casinhF s_csinhF s_catanhF s_catanF \ s_ctanF s_ctanhF s_cexpF s_clogF s_cprojF s_csqrtF \ s_cpowF s_clog10F s_fdimF s_nextdownF s_fmaxF s_fminF \ - s_nanF s_iseqsigF s_canonicalizeF w_ilogbF + s_nanF s_iseqsigF s_canonicalizeF w_ilogbF w_llogbF libm-calls = \ e_acosF e_acoshF e_asinF e_atan2F e_atanhF e_coshF e_expF e_fmodF \ @@ -159,7 +159,7 @@ tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \ test-fesetexcept-traps test-fetestexceptflag test-femode \ test-femode-traps test-iszero-excess-precision \ test-iseqsig-excess-precision test-flt-eval-method \ - test-fp-ilogb-constants $(tests-static) + test-fp-ilogb-constants test-fp-llogb-constants $(tests-static) tests-static = test-fpucw-static test-fpucw-ieee-static \ test-signgam-uchar-static test-signgam-uchar-init-static \ test-signgam-uint-static test-signgam-uint-init-static \ diff --git a/math/Versions b/math/Versions index 143e53f052..6fe9bb7e6f 100644 --- a/math/Versions +++ b/math/Versions @@ -223,5 +223,6 @@ libm { canonicalize; canonicalizef; canonicalizel; setpayload; setpayloadf; setpayloadl; setpayloadsig; setpayloadsigf; setpayloadsigl; + llogb; llogbf; llogbl; } } diff --git a/math/bits/mathcalls.h b/math/bits/mathcalls.h index 54ea4b8f30..c57b5627cd 100644 --- a/math/bits/mathcalls.h +++ b/math/bits/mathcalls.h @@ -315,6 +315,11 @@ __MATHCALL (scalbn,, (_Mdouble_ __x, int __n)); __MATHDECL (int,ilogb,, (_Mdouble_ __x)); #endif +#if __GLIBC_USE (IEC_60559_BFP_EXT) +/* Like ilogb, but returning long int. */ +__MATHDECL (long int, llogb,, (_Mdouble_ __x)); +#endif + #ifdef __USE_ISOC99 /* Return X times (2 to the Nth power). */ __MATHCALL (scalbln,, (_Mdouble_ __x, long int __n)); diff --git a/math/libm-test.inc b/math/libm-test.inc index 81d114b04f..85df9deb86 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -50,7 +50,7 @@ ilogb, iscanonical, isfinite, isinf, isnan, isnormal, issignaling, issubnormal, iszero, iseqsig, isless, islessequal, isgreater, isgreaterequal, islessgreater, isunordered, j0, j1, jn, - ldexp, lgamma, log, log10, log1p, log2, logb, + ldexp, lgamma, llogb, log, log10, log1p, log2, logb, modf, nearbyint, nextafter, nexttoward, pow, pow10, remainder, remquo, rint, lrint, llrint, round, lround, llround, @@ -9171,6 +9171,48 @@ gamma_test (void) } +static const struct test_f_l_data llogb_test_data[] = + { + TEST_f_l (llogb, 1, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_l (llogb, lit_e, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_l (llogb, 1024, 10, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_l (llogb, -2000, 10, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_l (llogb, 0.5, -1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + TEST_f_l (llogb, -0.5, -1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + +#if MANT_DIG >= 57 + TEST_f_l (llogb, 0x1.ffffffffffffffp1L, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_f_l (llogb, -0x1.ffffffffffffffp1L, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), +#endif + + TEST_f_l (llogb, min_subnorm_value, MIN_EXP-MANT_DIG, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + TEST_f_l (llogb, -min_subnorm_value, MIN_EXP-MANT_DIG, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + TEST_f_l (llogb, min_value, MIN_EXP-1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + TEST_f_l (llogb, -min_value, MIN_EXP-1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + TEST_f_l (llogb, max_value, MAX_EXP-1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + TEST_f_l (llogb, -max_value, MAX_EXP-1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED); + + /* llogb (0.0) == FP_LLOGB0 plus invalid exception */ + TEST_f_l (llogb, 0.0, FP_LLOGB0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + TEST_f_l (llogb, -0.0, FP_LLOGB0, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + /* llogb (qNaN) == FP_LLOGBNAN plus invalid exception */ + TEST_f_l (llogb, qnan_value, FP_LLOGBNAN, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + TEST_f_l (llogb, -qnan_value, FP_LLOGBNAN, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + TEST_f_l (llogb, snan_value, FP_LLOGBNAN, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + TEST_f_l (llogb, -snan_value, FP_LLOGBNAN, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + /* llogb (inf) == LONG_MAX plus invalid exception */ + TEST_f_l (llogb, plus_infty, LONG_MAX, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + /* llogb (-inf) == LONG_MAX plus invalid exception */ + TEST_f_l (llogb, minus_infty, LONG_MAX, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM), + }; + +static void +llogb_test (void) +{ + ALL_RM_TEST (llogb, 1, llogb_test_data, RUN_TEST_LOOP_f_l, END); +} + + static const struct test_f_l_data lrint_test_data[] = { /* Bug 6798: errno setting may be missing. */ @@ -13775,6 +13817,7 @@ main (int argc, char **argv) modf_test (); pow10_test (); ilogb_test (); + llogb_test (); scalb_test (); scalbn_test (); scalbln_test (); diff --git a/math/math.h b/math/math.h index 6e4bf9e528..b8f4b415c7 100644 --- a/math/math.h +++ b/math/math.h @@ -97,11 +97,13 @@ typedef _Float128x double_t; # endif #endif -/* Define macros for the return value of ilogb, based on +/* Define macros for the return values of ilogb and llogb, based on __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN. FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'. FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'. + FP_LLOGB0 Expands to a value returned by `llogb (0.0)'. + FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'. */ @@ -118,6 +120,23 @@ typedef _Float128x double_t; # define FP_ILOGBNAN 2147483647 # endif #endif +#if __GLIBC_USE (IEC_60559_BFP_EXT) +# if __WORDSIZE == 32 +# define __FP_LONG_MAX 0x7fffffffL +# else +# define __FP_LONG_MAX 0x7fffffffffffffffL +# endif +# if __FP_LOGB0_IS_MIN +# define FP_LLOGB0 (-__FP_LONG_MAX - 1) +# else +# define FP_LLOGB0 (-__FP_LONG_MAX) +# endif +# if __FP_LOGBNAN_IS_MIN +# define FP_LLOGBNAN (-__FP_LONG_MAX - 1) +# else +# define FP_LLOGBNAN __FP_LONG_MAX +# endif +#endif /* Get information about long double. */ diff --git a/math/test-fp-llogb-constants.c b/math/test-fp-llogb-constants.c new file mode 100644 index 0000000000..25bc0042f4 --- /dev/null +++ b/math/test-fp-llogb-constants.c @@ -0,0 +1,48 @@ +/* Test requirements on FP_LLOGB* constants. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <limits.h> +#include <math.h> + +#if FP_LLOGB0 >= 0 +# error "FP_LLOGB0 is positive" +#endif + +#if FP_LLOGB0 != LONG_MIN && FP_LLOGB0 != -LONG_MAX +# error "FP_LLOGB0 must be LONG_MIN or -LONG_MAX" +#endif + +#if FP_LLOGBNAN >= 0 && FP_LLOGBNAN != LONG_MAX +# error "FP_LLOGBNAN must be LONG_MIN or LONG_MAX" +#endif + +#if FP_LLOGBNAN < 0 && FP_LLOGBNAN != LONG_MIN +# error "FP_LLOGBNAN must be LONG_MIN or LONG_MAX" +#endif + +#if (FP_ILOGB0 == INT_MIN) != (FP_LLOGB0 == LONG_MIN) +# error "FP_ILOGB0 and FP_LLOGB0 inconsistent" +#endif + +#if (FP_ILOGBNAN == INT_MIN) != (FP_LLOGBNAN == LONG_MIN) +# error "FP_ILOGBNAN and FP_LLOGBNAN inconsistent" +#endif + +/* This is a compilation test. */ +#define TEST_FUNCTION 0 +#include "../test-skeleton.c" diff --git a/math/test-tgmath-ret.c b/math/test-tgmath-ret.c index 9f535b9774..d7bcb5c1b2 100644 --- a/math/test-tgmath-ret.c +++ b/math/test-tgmath-ret.c @@ -61,6 +61,7 @@ check_return_ ##func (void) \ } CHECK_RET_CONST(ilogb, int) +CHECK_RET_CONST(llogb, long) CHECK_RET_CONST(lrint, long) CHECK_RET_CONST(lround, long) CHECK_RET_CONST(llrint, long long) @@ -70,6 +71,7 @@ static int do_test (void) { check_return_ilogb (); + check_return_llogb (); check_return_lrint (); check_return_lround (); check_return_llrint (); diff --git a/math/test-tgmath.c b/math/test-tgmath.c index a919c64aab..be2c2fc3d4 100644 --- a/math/test-tgmath.c +++ b/math/test-tgmath.c @@ -50,7 +50,7 @@ int count_cdouble; int count_cfloat; int count_cldouble; -#define NCALLS 125 +#define NCALLS 126 #define NCALLS_INT 4 #define NCCALLS 47 @@ -281,6 +281,7 @@ F(compile_test) (void) a = scalb (scalb (x, a), (TYPE) (6)); k = scalbn (a, 7) + scalbln (c, 10l); i = ilogb (x); + j = llogb (x); a = fdim (fdim (x, a), fdim (c, b)); b = fmax (fmax (a, x), fmax (c, b)); a = fmin (fmin (x, a), fmin (c, b)); @@ -379,6 +380,7 @@ F(compile_test) (void) a = scalb (y, (const TYPE) (6)); k = scalbn (y, 7) + scalbln (y, 10l); i = ilogb (y); + j = llogb (y); a = fdim (y, y); a = fmax (y, y); a = fmin (y, y); @@ -846,6 +848,14 @@ int return x; } +long int +(F(llogb)) (TYPE x) +{ + ++count; + P (); + return x; +} + TYPE (F(fdim)) (TYPE x, TYPE y) { diff --git a/math/tgmath.h b/math/tgmath.h index 0d51ae60be..95f5f198ba 100644 --- a/math/tgmath.h +++ b/math/tgmath.h @@ -438,6 +438,9 @@ __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma) #if __GLIBC_USE (IEC_60559_BFP_EXT) +/* Like ilogb, but returning long int. */ +#define llogb(Val) __TGMATH_UNARY_REAL_RET_ONLY (Val, long int, llogb) + /* Total order operation. */ # define totalorder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \ totalorder) diff --git a/math/w_llogb_template.c b/math/w_llogb_template.c new file mode 100644 index 0000000000..9065bf9b4f --- /dev/null +++ b/math/w_llogb_template.c @@ -0,0 +1,46 @@ +/* Wrapper to implement llogb in terms of ilogb. + Copyright (C) 2012-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <errno.h> +#include <limits.h> +#include <math_private.h> + +long int +M_DECL_FUNC (__llogb) (FLOAT x) +{ + int r = M_SUF (__ieee754_ilogb) (x); + long int lr = r; + if (__glibc_unlikely (r == FP_ILOGB0) + || __glibc_unlikely (r == FP_ILOGBNAN) + || __glibc_unlikely (r == INT_MAX)) + { +#if LONG_MAX != INT_MAX + if (r == FP_ILOGB0) + lr = FP_LLOGB0; + else if (r == FP_ILOGBNAN) + lr = FP_LLOGBNAN; + else + lr = LONG_MAX; +#endif + __set_errno (EDOM); + __feraiseexcept (FE_INVALID); + } + return lr; +} +declare_mgen_alias (__llogb, llogb) |