diff options
| author | Joseph Myers <joseph@codesourcery.com> | 2016-12-02 01:42:49 +0000 |
|---|---|---|
| committer | Joseph Myers <joseph@codesourcery.com> | 2016-12-02 01:42:49 +0000 |
| commit | 55a38f82369669e181a05bcf2ac6c647dcd9b261 (patch) | |
| tree | 5ecf72dbb2673caa4e87a91b46fdc9a3af66db7d | |
| parent | 6dc07416777012947152edaf5b7848c9e62c2fc8 (diff) | |
| download | glibc-55a38f82369669e181a05bcf2ac6c647dcd9b261.tar.xz glibc-55a38f82369669e181a05bcf2ac6c647dcd9b261.zip | |
Add llogb, llogbf, llogbl.
TS 18661-1 defines llogb functions that are like ilogb except that
they return long int instead of int. Corresponding FP_LLOGB* macros
are defined, whose values are required to have the obvious
correspondence to those of the FP_ILOGB* macros.
This patch implements these functions and macros for glibc. llogb
uses the type-generic infrastructure, with an implementation similar
to the wrapper for ilogb but with additional conversion from FP_ILOGB*
to FP_LLOGB*; this approach avoids needing to modify or duplicate any
of the architecture-specific ilogb implementations. Tests are also
based on those for ilogb.
Ideally the llogb functions would alias the ilogb ones when long is
32-bit, but such aliasing requires the associated header declarations
of the different-type alias to be hidden, typically by defining macros
before including the header (see e.g. how
sysdeps/ieee754/dbl-64/wordsize-64/s_llround.c defines lround to
__hidden_lround before including <math.h>). The infrastructure for
type-generic function implementations does not support defining such
macros at present (since C code can't define a macro whose name is
determined by other macros). So this patch leaves them as separate
functions (similar to e.g. scalbln and scalbn being separate in such a
case as well), but with the remapping of FP_ILOGB* to FP_LLOGB*
conditioned out in the case where it would be the identity map.
Tested for x86_64, x86, mips64 and powerpc.
* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb):
New declaration.
* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb): New
macro.
* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (__FP_LONG_MAX):
New macro.
[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGB0): Likewise.
[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGBNAN): Likewise.
* math/Versions (llogb): New libm symbol at version GLIBC_2.25.
(llogbf): Likewise.
(llogbl): Likewise.
* math/Makefile (gen-libm-calls): Add w_llogbF.
(tests): Add test-fp-llogb-constants.
* math/w_llogb_template.c: New file. Based on
math/w_ilogb_template.c.
* math/libm-test.inc (llogb_test_data): New array.
(llogb_test): New function.
(main): Call llogb_test.
* math/test-fp-llogb-constants.c: New file. Based on
math/test-fp-ilogb-constants.c.
* math/test-tgmath-ret.c (llogb): New CHECK_RET_CONST call.
(do_test): Call check_return_llogb.
* math/test-tgmath.c (NCALLS): Increase to 126.
(F(compile_test)): Call llogb.
(F(llogb)): New function.
* manual/math.texi (Exponents and Logarithms): Document llogb,
llogbf, llogbl, FP_LLOGB0 and FP_LLOGBNAN.
* manual/libm-err-tab.pl (@all_functions): Add llogb.
* sysdeps/ieee754/ldbl-opt/nldbl-llogb.c: New file.
* sysdeps/ieee754/ldbl-opt/w_llogbl.c: Likewise.
* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add llogb.
(CFLAGS-nldbl-llogb.c): New variable.
* sysdeps/nacl/libm.abilist: Update.
* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
44 files changed, 398 insertions, 8 deletions
@@ -1,3 +1,71 @@ +2016-12-02 Joseph Myers <joseph@codesourcery.com> + + * math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb): + New declaration. + * math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb): New + macro. + * math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (__FP_LONG_MAX): + New macro. + [__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGB0): Likewise. + [__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGBNAN): Likewise. + * math/Versions (llogb): New libm symbol at version GLIBC_2.25. + (llogbf): Likewise. + (llogbl): Likewise. + * math/Makefile (gen-libm-calls): Add w_llogbF. + (tests): Add test-fp-llogb-constants. + * math/w_llogb_template.c: New file. Based on + math/w_ilogb_template.c. + * math/libm-test.inc (llogb_test_data): New array. + (llogb_test): New function. + (main): Call llogb_test. + * math/test-fp-llogb-constants.c: New file. Based on + math/test-fp-ilogb-constants.c. + * math/test-tgmath-ret.c (llogb): New CHECK_RET_CONST call. + (do_test): Call check_return_llogb. + * math/test-tgmath.c (NCALLS): Increase to 126. + (F(compile_test)): Call llogb. + (F(llogb)): New function. + * manual/math.texi (Exponents and Logarithms): Document llogb, + llogbf, llogbl, FP_LLOGB0 and FP_LLOGBNAN. + * manual/libm-err-tab.pl (@all_functions): Add llogb. + * sysdeps/ieee754/ldbl-opt/nldbl-llogb.c: New file. + * sysdeps/ieee754/ldbl-opt/w_llogbl.c: Likewise. + * sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add llogb. + (CFLAGS-nldbl-llogb.c): New variable. + * sysdeps/nacl/libm.abilist: Update. + * sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist: + Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist: + Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist: + Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist: + Likewise. + * sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist: + Likewise. + * sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist: + Likewise. + * sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise. + * sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise. + 2016-12-01 Joseph Myers <joseph@codesourcery.com> * sysdeps/ieee754/ldbl-128/s_getpayloadl.c (getpayloadl): Use @@ -53,6 +53,9 @@ Version 2.25 - Signaling NaN macros: SNANF, SNAN, SNANL. + - llogb functions: the llogb, llogbf and llogbl functions, and the + FP_LLOGB0 and FP_LLOGBNAN macros. + - Comparison macros: iseqsig. - Classification macros: iscanonical, issubnormal, iszero. diff --git a/manual/libm-err-tab.pl b/manual/libm-err-tab.pl index 6d0bffc372..0e83853949 100755 --- a/manual/libm-err-tab.pl +++ b/manual/libm-err-tab.pl @@ -58,7 +58,7 @@ use vars qw (%results @all_floats %suffices @all_functions); "creal", "csin", "csinh", "csqrt", "ctan", "ctanh", "erf", "erfc", "exp", "exp10", "exp2", "expm1", "fabs", "fdim", "floor", "fma", "fmax", "fmin", "fmod", "frexp", "gamma", "hypot", - "ilogb", "j0", "j1", "jn", "lgamma", "lrint", + "ilogb", "j0", "j1", "jn", "lgamma", "llogb", "lrint", "llrint", "log", "log10", "log1p", "log2", "logb", "lround", "llround", "modf", "nearbyint", "nextafter", "nextdown", "nexttoward", "nextup", "pow", "remainder", "remquo", "rint", "round", "scalb", diff --git a/manual/math.texi b/manual/math.texi index b4bb32345e..5ad8732eca 100644 --- a/manual/math.texi +++ b/manual/math.texi @@ -584,9 +584,20 @@ negative), @code{logb} returns @math{@infinity{}}. If @var{x} is zero, @comment math.h @comment ISO @deftypefunx int ilogbl (long double @var{x}) +@comment math.h +@comment ISO +@deftypefunx {long int} llogb (double @var{x}) +@comment math.h +@comment ISO +@deftypefunx {long int} llogbf (float @var{x}) +@comment math.h +@comment ISO +@deftypefunx {long int} llogbl (long double @var{x}) @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} These functions are equivalent to the corresponding @code{logb} -functions except that they return signed integer values. +functions except that they return signed integer values. The +@code{ilogb} functions are from ISO C99; the @code{llogb} functions +are from TS 18661-1:2014. @end deftypefun @noindent @@ -605,6 +616,15 @@ This macro is defined in @w{ISO C99}. @comment math.h @comment ISO +@deftypevr Macro {long int} FP_LLOGB0 +@code{llogb} returns this value if its argument is @code{0}. The +numeric value is either @code{LONG_MIN} or @code{-LONG_MAX}. + +This macro is defined in TS 18661-1:2014. +@end deftypevr + +@comment math.h +@comment ISO @deftypevr Macro int FP_ILOGBNAN @code{ilogb} returns this value if its argument is @code{NaN}. The numeric value is either @code{INT_MIN} or @code{INT_MAX}. @@ -612,6 +632,15 @@ numeric value is either @code{INT_MIN} or @code{INT_MAX}. This macro is defined in @w{ISO C99}. @end deftypevr +@comment math.h +@comment ISO +@deftypevr Macro {long int} FP_LLOGBNAN +@code{llogb} returns this value if its argument is @code{NaN}. The +numeric value is either @code{LONG_MIN} or @code{LONG_MAX}. + +This macro is defined in TS 18661-1:2014. +@end deftypevr + These values are system specific. They might even be the same. The proper way to test the result of @code{ilogb} is as follows: 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); + |
