Commit Graph

7 Commits

Author SHA1 Message Date
Joseph Myers 29cb929332 Add iscanonical.
TS 18661-1 adds an iscanonical classification macro to <math.h>.

The motivation for this is decimal floating-point, where some values
have both canonical and noncanonical encodings.  For IEEE binary
interchange formats, all encodings are canonical.  For x86/m68k
ldbl-96, and for ldbl-128ibm, there are encodings that do not
represent any valid value of the type; although formally iscanonical
does not need to handle trap representations (and so could just always
return 1), it seems useful, and in line with the description in the TS
of "representations that are extraneous to the floating-point model"
as being non-canonical (as well as "redundant representations of some
or all of its values"), for it to detect those representations and
return 0 for them.

This patch adds iscanonical to glibc.  It goes in a header
<bits/iscanonical.h>, included under appropriate conditions in
<math.h>.  The default header version just evaluates the argument
(converted to its semantic type, though current GCC will probably
discard that conversion and any exceptions resulting from it) and
returns 1.  ldbl-96 and ldbl-128ibm then have versions of the header
that call a function __iscanonicall for long double (the sizeof-based
tests will of course need updating for float128 support, like other
such type-generic macro implementations).  The ldbl-96 version of
__iscanonicall has appropriate conditionals to reflect the differences
in the m68k version of that format (where the high mantissa bit may be
either 0 or 1 when the exponent is 0 or 0x7fff).  Corresponding tests
for those formats are added as well.  Other architectures do not have
any new functions added because just returning 1 is correct for all
their floating-point formats.

Tested for x86_64, x86, mips64 (to test the default macro version) and
powerpc.

	* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)]: Include
	<bits/iscanonical.h>.
	* bits/iscanonical.h: New file.
	* math/s_iscanonicall.c: Likewise.
	* math/Versions (__iscanonicall): New libm symbol at version
	GLIBC_2.25.
	* math/libm-test.inc (iscanonical_test_data): New array.
	(iscanonical_test): New function.
	(main): Call iscanonical_test.
	* math/Makefile (headers): Add bits/iscanonical.h.
	(type-ldouble-routines): Add s_iscanonicall.
	* manual/arith.texi (Floating Point Classes): Document
	iscanonical.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_iscanonicall.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/test-iscanonical-ldbl-128ibm.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm/Makefile (tests): Add
	test-iscanonical-ldbl-128ibm.
	* sysdeps/ieee754/ldbl-96/bits/iscanonical.h: New file.
	* sysdeps/ieee754/ldbl-96/s_iscanonicall.c: Likewise.
	* sysdeps/ieee754/ldbl-96/test-iscanonical-ldbl-96.c: Likewise.
	* sysdeps/ieee754/ldbl-96/Makefile: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/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/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-09-30 00:27:50 +00:00
Joseph Myers cc4084017e Fix ldbl-128ibm remainderl equality test for zero low part (bug 19677).
The ldbl-128ibm implementation of remainderl has logic resulting in
incorrect tests for equality of the absolute values of the arguments
in the case of zero low parts.  If the low parts are both zero but
with different signs, this can wrongly cause equal arguments to be
treated as different, resulting in turn in incorrect signs of zero
result in nondefault rounding modes arising from the subtractions done
when the arguments are not equal.

This patch fixes the logic to convert -0 low parts into +0 before the
comparison (remquo already has separate logic to deal with signs of
zero results, so doesn't need such a change).  Tests are added for
remainderl and remquol similar to that for fmodl, and based on a
refactoring of it, since the bug depends on low parts which should not
be relied upon in tests not setting the representation explicitly
(although in fact the bug shows up in test-ldouble with current GCC).
Tested for powerpc.

	[BZ #19677]
	* sysdeps/ieee754/ldbl-128ibm/e_remainderl.c
	(__ieee754_remainderl): Put zero low parts in canonical form.
	* sysdeps/ieee754/ldbl-128ibm/test-fmodrem-ldbl-128ibm.c: New
	file.  Based on
	sysdeps/ieee754/ldbl-128ibm/test-fmodl-ldbl-128ibm.c.
	* sysdeps/ieee754/ldbl-128ibm/test-fmodl-ldbl-128ibm.c: Replace
	with wrapper round test-fmodrem-ldbl-128ibm.c.
	* sysdeps/ieee754/ldbl-128ibm/test-remainderl-ldbl-128ibm.c: New
	file.
	* sysdeps/ieee754/ldbl-128ibm/test-remquol-ldbl-128ibm.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm/Makefile (tests): Add
	test-remainderl-ldbl-128ibm and test-remquol-ldbl-128ibm.
2016-03-08 00:27:21 +00:00
Joseph Myers 0fed79a827 Fix ldbl-128ibm fmodl handling of equal arguments with low part zero (bug 19602).
The ldbl-128ibm implementation of fmodl has logic to detect when the
first argument has absolute value less than or equal to the second.
This logic is only correct for nonzero low parts; if the high parts
are equal and the low parts are zero, then the signs of the low parts
(which have no semantic effect on the value of the long double number)
can result in equal values being wrongly treated as unequal, and an
incorrect result being returned from fmodl.  This patch fixes this by
checking for the case of zero low parts.

Although this does show up in tests from libm-test.inc (both tests of
fmodl, and, indirectly, of remainderl / dreml), the dependence on
non-semantic zero low parts means that test shouldn't be expected to
reproduce it reliably; thus, this patch adds a standalone test that
sets up affected values using unions.

Tested for powerpc.

	[BZ #19602]
	* sysdeps/ieee754/ldbl-128ibm/e_fmodl.c (__ieee754_fmodl): Handle
	equal high parts and both low parts zero specially.
	* sysdeps/ieee754/ldbl-128ibm/test-fmodl-ldbl-128ibm.c: New test.
	* sysdeps/ieee754/ldbl-128ibm/Makefile [$(subdir) = math] (tests):
	Add test-fmodl-ldbl-128ibm.
2016-02-18 22:54:07 +00:00
Joseph Myers 909f8e14db Fix ldbl-128ibm strtold overflow handling (bug 14551).
For ldbl-128ibm, if the result of strtold overflows in the final
conversion from MPN to IBM long double (because the exponent for a
106-bit IEEE result is 1023 but the high part would end up as
0x1p1024, which overflows), that conversion code fails to handle this
and produces an invalid long double value (high part infinite, low
part not zero) without raising exceptions or setting errno.  This
patch adds an explicit check for this case to ensure an appropriate
result is returned in a way that ensures the right exceptions are
raised, with errno set.

Tested for powerpc.

	[BZ #14551]
	* sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c: Include <errno.h>.
	(__mpn_construct_long_double): If high part overflows to infinity,
	set errno and recompute overflowed result of the correct sign.
	* sysdeps/ieee754/ldbl-128ibm/Makefile
	[$(subdir) = stdlib] (tests): Add tst-strtold-ldbl-128ibm.
	[$(subdir) = stdlib] ($(objpfx)tst-strtold-ldbl-128ibm): Depend on
	$(libm).
	* sysdeps/ieee754/ldbl-128ibm/tst-strtold-ldbl-128ibm.c: New file.
2015-11-13 12:03:46 +00:00
Roland McGrath f964490f3c 2006-01-27 Dwayne Grant McConnell <decimal@us.ibm.com>
Jakub Jelinek  <jakub@redhat.com>
	    Roland McGrath  <roland@redhat.com>
	    Steven Munroe  <sjmunroe@us.ibm.com>
	    Alan Modra  <amodra@bigpond.net.au>

	* sysdeps/powerpc/powerpc64/fpu/s_truncf.S: Comment fix.
	* sysdeps/powerpc/powerpc32/fpu/s_truncf.S: Likewise.
	* sysdeps/powerpc/powerpc64/fpu/s_llroundf.S: Likewise.

	* sysdeps/powerpc/fpu/libm-test-ulps: Update.

	* math/libm-test.inc (check_float_internal): Allow ulp <= 0.5.
	(erfc_test): Don't run erfcl (27.0L) test if erfcl (27.0L) is
	denormal.
	[TEST_LDOUBLE] (ceil_test, floor_test, llrint_test, llround_test,
	rint_test, round_test, trunc_test): Add new tests.

	* sysdeps/powerpc/powerpc32/fpu/s_copysignl.S: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_fabs.S: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_fabsl.S: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_fdim.c: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_fmax.S: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_fmin.S: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_isnan.c: New file.

	* sysdeps/powerpc/powerpc64/fpu/s_ceill.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_copysignl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_fabs.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_fabsl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_fdim.c: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_floorl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_fmax.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_fmin.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_isnan.c: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_llrintl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_llroundl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_lrintl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_lroundl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_nearbyintl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_rintl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_roundl.S: New file.
	* sysdeps/powerpc/powerpc64/fpu/s_truncl.S: New file.

	* sysdeps/unix/sysv/linux/powerpc/Implies: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fpu/Implies: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/Implies: New file.
	* sysdeps/unix/sysv/linux/powerpc/configure.in: New file.
	* sysdeps/unix/sysv/linux/powerpc/configure: New file.
	* sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
	(__LONG_DOUBLE_MATH_OPTIONAL): Define.
	(__NO_LONG_DOUBLE_MATH): Define.
	* sysdeps/unix/sysv/linux/powerpc/nldbl-abi.h: New file.
	* sysdeps/powerpc/fpu/s_isnan.c: Include math_ldbl_opt.h.
	* sysdeps/powerpc/powerpc64/fpu/s_ceil.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (ceill): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_copysign.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (copysignl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_floor.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (floorl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_llrint.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (llrintl, lrintl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_llround.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (llroundl, lroundl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_rint.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (rintl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_round.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (roundl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc64/fpu/s_trunc.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (truncl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_ceil.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (ceill): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_copysign.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (copysignl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_floor.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (floorl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_lrint.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (lrintl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_llrint.c: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (llrintl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_lround.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (lroundl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_rint.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (rintl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_round.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (roundl): Add compatibility symbols.
	* sysdeps/powerpc/powerpc32/fpu/s_trunc.S: Include math_ldbl_opt.h.
	[LONG_DOUBLE_COMPAT] (truncl): Add compatibility symbols.

	* misc/qefgcvt_r.c [LDBL_MIN_10_EXP == -291] (FLOAT_MIN_10_NORM): New.

	* sysdeps/powerpc/fpu/bits/mathdef.h (__NO_LONG_DOUBLE_MATH): Remove.
	* sysdeps/powerpc/Implies: Add ieee754/ldbl-128ibm.
	* sysdeps/powerpc/powerpc32/Implies: Remove powerpc/soft-fp.
	* sysdeps/ieee754/ldbl-128ibm/Makefile: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_acoshl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_acosl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_asinl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_atan2l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_atanhl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_coshl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_expl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_fmodl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_gammal_r.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_hypotl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_j0l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_j1l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_jnl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_lgammal_r.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_log10l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_log2l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_logl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_powl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_rem_pio2l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_remainderl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_sinhl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/e_sqrtl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/ieee754.h: New file.
	* sysdeps/ieee754/ldbl-128ibm/k_cosl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/k_sincosl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/k_sinl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/k_tanl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/math_ldbl.h: New file.
	* sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/printf_fphex.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_asinhl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_atanl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_cbrtl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_cosl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_erfl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_expm1l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_fabsl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_finitel.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_fpclassifyl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_frexpl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_ilogbl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_isinfl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_isnanl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_log1pl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_logbl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_modfl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_nexttowardf.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_remquol.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_rintl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_scalblnl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_signbitl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_sincosl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_sinl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_tanhl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_tanl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_truncl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/strtold_l.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/t_sincosl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/w_expl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_copysignl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_floorl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_llrintl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_llroundl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_roundl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_ceill.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_lrintl.c: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_lroundl.c: New file.

	* sysdeps/ieee754/ldbl-128/e_powl.c: Fix old comment.
2006-01-28 00:15:15 +00:00
Ulrich Drepper a334319f65 (CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4. 2004-12-22 20:10:10 +00:00
Jakub Jelinek 0ecb606cb6 2.5-18.1 2007-07-12 18:26:36 +00:00