Commit Graph

1075 Commits

Author SHA1 Message Date
Joseph Myers 228a78c21b Fix i386 fdim double rounding (bug 20255).
fdim suffers from double rounding on i386 because subtracting two
double values can produce an inexact long double value exactly half
way between two double values.  This patch fixes this by creating an
i386-specific version of fdim - C, based on the generic version,
unlike the previous .S version - which sets the x87 precision control
to double precision for the subtraction and then restores it
afterwards.  As noted in the comment added, there are no issues of
double rounding for subnormals (a case that setting precision control
does not address) because subtraction cannot produce an inexact result
in the subnormal range.

Tested for x86_64 and x86.

	[BZ #20255]
	* sysdeps/i386/fpu/s_fdim.c: New file.  Based on math/s_fdim.c.
	* math/libm-test.inc (fdim_test_data): Add another test.
2016-06-14 16:41:50 +00:00
Joseph Myers f4015c8a86 Use generic fdim on more architectures (bug 6796, bug 20255, bug 20256).
Some architectures have their own versions of fdim functions, which
are missing errno setting (bug 6796) and may also return sNaN instead
of qNaN for sNaN input, in the case of the x86 / x86_64 long double
versions (bug 20256).

These versions are not actually doing anything that a compiler
couldn't generate, just straightforward comparisons / arithmetic (and,
in the x86 / x86_64 case, testing for NaNs with fxam, which isn't
actually needed once you use an unordered comparison and let the NaNs
pass through the same subtraction as non-NaN inputs).  This patch
removes the x86 / x86_64 / powerpc versions, so that those
architectures use the generic C versions, which correctly handle
setting errno and deal properly with sNaN inputs.  This seems better
than dealing with setting errno in lots of .S versions.

The i386 versions also return results with excess range and precision,
which is not appropriate for a function exactly defined by reference
to IEEE operations.  For errno setting to work correctly on overflow,
it's necessary to remove excess range with math_narrow_eval, which
this patch duly does in the float and double versions so that the
tests can reliably pass on x86.  For float, this avoids any double
rounding issues as the long double precision is more than twice that
of float.  For double, double rounding issues will need to be
addressed separately, so this patch does not fully fix bug 20255.

Tested for x86_64, x86 and powerpc.

	[BZ #6796]
	[BZ #20255]
	[BZ #20256]
	* math/s_fdim.c: Include <math_private.h>.
	(__fdim): Use math_narrow_eval on result.
	* math/s_fdimf.c: Include <math_private.h>.
	(__fdimf): Use math_narrow_eval on result.
	* sysdeps/i386/fpu/s_fdim.S: Remove file.
	* sysdeps/i386/fpu/s_fdimf.S: Likewise.
	* sysdeps/i386/fpu/s_fdiml.S: Likewise.
	* sysdeps/i386/i686/fpu/s_fdim.S: Likewise.
	* sysdeps/i386/i686/fpu/s_fdimf.S: Likewise.
	* sysdeps/i386/i686/fpu/s_fdiml.S: Likewise.
	* sysdeps/powerpc/fpu/s_fdim.c: Likewise.
	* sysdeps/powerpc/fpu/s_fdimf.c: Likewise.
	* sysdeps/powerpc/powerpc32/fpu/s_fdim.c: Likewise.
	* sysdeps/powerpc/powerpc64/fpu/s_fdim.c: Likewise.
	* sysdeps/x86_64/fpu/s_fdiml.S: Likewise.
	* math/libm-test.inc (fdim_test_data): Expect errno setting on
	overflow.  Add sNaN tests.
2016-06-14 16:04:19 +00:00
Joseph Myers 4fea2cda61 Simplify generic fdim implementations.
The generic fdim implementations have unnecessarily complicated code,
using fpclassify to determine whether the arguments are NaNs,
subtracting NaNs if so and otherwise subtracting the non-NaN arguments
if not (x <= y), then using fpclassify on the result to see if it is
infinite.

This patch simplifies the code.  Instead of handling NaNs separately,
it suffices to use an unordered comparison with islessequal (x, y) to
determine whether to return zero, and otherwise NaNs can go through
the same subtraction as non-NaN arguments; no explicit tests for NaN
are needed at all.  Then, isinf instead of fpclassify can be used to
determine whether to set errno (in the normal non-overflow case, only
one classification will need to occur, unlike the three in the
previous code, of which two occurred even if returning zero, because
the result will not be infinite in the normal case).

The resulting logic is essentially the same as that in the powerpc
version, except that the powerpc version is missing errno setting and
uses <= not islessequal, so relying on
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58684>, the GCC bug that
unordered comparison instructions are wrongly used on powerpc for
ordered comparisons.

The compiled code for fdim and fdimf on x86_64 is less than half the
size of the previous code.

Tested for x86_64.

	* math/s_fdim.c (__fdim): Use islessequal and isinf instead of
	fpclassify.
	* math/s_fdimf.c (__fdimf): Likewise.
	* math/s_fdiml.c (__fdiml): Likewise.
2016-06-14 14:56:42 +00:00
Joseph Myers a2ae1696f7 Fix dbl-64 atan2 (sNaN, qNaN) (bug 20252).
The dbl-64 implementation of atan2, passed arguments (sNaN, qNaN),
fails to raise the "invalid" exception.  This patch fixes it to add
both arguments, rather than just adding the second argument to itself,
in the case where the second argument is a NaN (which is checked for
before checking for the first argument being a NaN).  sNaN tests for
atan2 are added, along with some qNaN tests I noticed were missing but
should have been there by analogy with other tests present.

Tested for x86_64 and x86.

	[BZ #20252]
	* sysdeps/ieee754/dbl-64/e_atan2.c (__ieee754_atan2): Add both
	arguments when second argument is a NaN.
	* math/libm-test.inc (atan2_test_data): Add sNaN tests and more
	qNaN tests.
2016-06-13 21:43:22 +00:00
Joseph Myers 5e19c4347f Add more sNaN tests (cimag, conj, copysign, creal, fma, fmod).
This patch adds tests of sNaN inputs to further libm functions.

Tested for x86_64 and x86.

	* math/libm-test.inc (cimag_test_data): Add sNaN tests.
	(conj_test_data): Likewise.
	(copysign_test_data): Likewise.
	(creal_test_data): Likewise.
	(fma_test_data): Likewise.
	(fmod_test_data): Likewise.
2016-06-13 21:26:28 +00:00
Joseph Myers 88283451b2 Fix frexp (NaN) (bug 20250).
Various implementations of frexp functions return sNaN for sNaN
input.  This patch fixes them to add such arguments to themselves so
that qNaN is returned.

Tested for x86_64, x86, mips64 and powerpc.

	[BZ #20250]
	* sysdeps/i386/fpu/s_frexpl.S (__frexpl): Add non-finite input to
	itself.
	* sysdeps/ieee754/dbl-64/s_frexp.c (__frexp): Add non-finite or
	zero input to itself.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_frexp.c (__frexp):
	Likewise.
	* sysdeps/ieee754/flt-32/s_frexpf.c (__frexpf): Likewise.
	* sysdeps/ieee754/ldbl-128/s_frexpl.c (__frexpl): Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_frexpl.c (__frexpl): Likewise.
	* sysdeps/ieee754/ldbl-96/s_frexpl.c (__frexpl): Likewise.
	* math/libm-test.inc (frexp_test_data): Add sNaN tests.
2016-06-13 17:27:19 +00:00
Joseph Myers a6a4395d20 Fix modf (sNaN) (bug 20240).
Various modf implementations return sNaN (both outputs) for sNaN
input.  In fact they contain code to convert sNaN to qNaN for both
outputs, but the way this is done is multiplying by 1.0 (for a wider
range of inputs that includes NaNs as well as numbers with exponent
large enough to ensure that they are integers), and that
multiplication by 1.0 is optimized away by GCC in the absence of
-fsignaling-nans, unlike other operations on NaNs used for this
purpose that are not no-ops for non-sNaN input.  This patch arranges
for those files to be built with -fsignaling-nans so that this
existing code is effective as intended.

Tested for x86_64 and x86.

	[BZ #20240]
	* math/Makefile (CFLAGS-s_modf.c): New variable.
	(CFLAGS-s_modff.c): Likewise.
	(CFLAGS-s_modfl.c): Likewise.
	* math/libm-test.inc (modf_test_data): Add sNaN tests.
2016-06-10 23:16:27 +00:00
Joseph Myers f00faa4a43 Fix i386/x86_64 log2l (sNaN) (bug 20235).
The i386/x86_64 versions of log2l return sNaN for sNaN input.  This
patch fixes them to add NaN inputs to themselves so that qNaN is
returned in this case.

Tested for x86_64 and x86.

	[BZ #20235]
	* sysdeps/i386/fpu/e_log2l.S (__ieee754_log2l): Add NaN input to
	itself.
	* sysdeps/x86_64/fpu/e_log2l.S (__ieee754_log2l): Likewise.
	* math/libm-test.inc (log2_test_data): Add sNaN tests.
2016-06-09 18:04:30 +00:00
Joseph Myers 8c010e2f71 Fix i386/x86_64 log1pl (sNaN) (bug 20229).
The i386/x86_64 versions of log1pl return sNaN for sNaN input.  This
patch fixes them to add a NaN input to itself so that qNaN is returned
in this case.

Tested for x86_64 and x86.

	[BZ #20229]
	* sysdeps/i386/fpu/s_log1pl.S (__log1pl): Add NaN input to itself.
	* sysdeps/x86_64/fpu/s_log1pl.S (__log1pl): Likewise.
	* math/libm-test.inc (log1p_test_data): Add sNaN tests.
2016-06-08 23:11:42 +00:00
Joseph Myers 09096b3615 Fix i386/x86_64 log10l (sNaN) (bug 20228).
The i386/x86_64 versions of log10l return sNaN for sNaN input.  This
patch fixes them to add a NaN input to itself so that qNaN is returned
in this case.

Tested for x86_64 and x86.

	[BZ #20228]
	* sysdeps/i386/fpu/e_log10l.S (__ieee754_log10l): Add NaN input to
	itself.
	* sysdeps/x86_64/fpu/e_log10l.S (__ieee754_log10l): Likewise.
	* math/libm-test.inc (log10_test_data): Add sNaN tests.
2016-06-08 22:59:18 +00:00
Joseph Myers df179d8808 Fix i386/x86_64 logl (sNaN) (bug 20227).
The i386/x86_64 versions of logl return sNaN for sNaN input.  This
patch fixes them to add a NaN input to itself so that qNaN is returned
in this case.

Tested for x86_64 and x86 (including a build for i586 to cover the
non-i686 logl version).

	[BZ #20227]
	* sysdeps/i386/fpu/e_logl.S (__ieee754_logl): Add NaN input to
	itself.
	* sysdeps/i386/i686/fpu/e_logl.S (__ieee754_logl): Likewise.
	* sysdeps/x86_64/fpu/e_logl.S (__ieee754_logl): Likewise.
	* math/libm-test.inc (log_test_data): Add sNaN tests.
2016-06-08 22:24:06 +00:00
Joseph Myers 9bd3ef8e19 Fix i386/x86_64 expl, exp10l, expm1l for sNaN input (bug 20226).
The i386 and x86_64 implementations of expl, exp10l and expm1l (code
shared between the functions) return sNaN for sNaN input.  This patch
fixes them to add NaN inputs to themselves so that qNaN is returned in
this case.

Tested for x86_64 and x86.

	[BZ #20226]
	* sysdeps/i386/fpu/e_expl.S (IEEE754_EXPL): Add NaN argument to
	itself.
	* sysdeps/x86_64/fpu/e_expl.S (IEEE754_EXPL): Likewise.
	* math/libm-test.inc (exp_test_data): Add sNaN tests.
	(exp10_test_data): Likewise.
	(expm1_test_data): Likewise.
2016-06-08 21:55:06 +00:00
Joseph Myers 9946e7a949 Fix ldexp, scalbn, scalbln for sNaN input (bug 20225).
The wrapper implementations of ldexp / scalbn / scalbln
(architecture-independent), and their float / long double variants,
return sNaN for sNaN input.  This patch fixes them to add relevant
arguments to themselves so that qNaN is returned in this case.

Tested for x86_64 and x86.

	[BZ #20225]
	* math/s_ldexp.c (__ldexp): Add non-finite or zero argument to
	itself.
	* math/s_ldexpf.c (__ldexpf): Likewise.
	* math/s_ldexpl.c (__ldexpl): Likewise.
	* math/w_scalbln.c (__w_scalbln): Likewise.
	* math/w_scalblnf.c (__w_scalblnf): Likewise.
	* math/w_scalblnl.c (__w_scalblnl): Likewise.
	* math/libm-test.inc (scalbn_test_data): Add sNaN tests.
	(scalbln_test_data): Likewise.
2016-06-08 21:32:57 +00:00
Joseph Myers 40720ec9f9 Fix i386 cbrtl (sNaN) (bug 20224).
The i386 version of cbrtl returns sNaN (without raising any
exceptions) for sNaN input.  This patch fixes it to add non-finite
arguments to themselves (the code path in question is also reached for
zero arguments, for which adding them to themselves is also harmless),
so that "invalid" is raised and qNaN returned.

Tested for x86_64 and x86.

	[BZ #20224]
	* sysdeps/i386/fpu/s_cbrtl.S (__cbrtl): Add non-finite or zero
	argument to itself.
	* math/libm-test.inc (cbrt_test_data): Add sNaN tests.
2016-06-08 21:02:40 +00:00
Paul E. Murphy 5188b97325 Generate new format names in auto-libm-test-out
This converts the inclusion macro for each test to use
the format specific macro. In addition, the format
specifier is removed as it is applied via the LIT() macro
which is itself applied when converting the auto inputs and
libm-test.inc into libm-test.c.
2016-06-08 14:56:04 -05:00
Paul E. Murphy 760723ec6e Remove type specific information from auto-libm-test-in
Apply the following sed regexes to auto-libm-test-in in order:

s/flt-32/binary32/
s/dbl-64/binary64/
s/ldbl-96-intel/intel96/
s/ldbl-96-m68k/m68k96/
s/ldbl-128ibm/ibm128/
s/ldbl-128/binary128/

and fixup ldbl-96 comment manually.
2016-06-08 14:41:05 -05:00
Paul E. Murphy 9c665e085f Remove CHOOSE() macro from libm-tests.inc
Use gen-libm-test.pl to generate a list of macros
mapping to libm-test-ulps.h as this simplifies adding new
types without having to modify a growing number of
static headers each time a type is added.

This also removes the final usage of the TEST_(DOUBLE|FLOAT|LDOUBLE)
macros.  Thus, they too are removed.
2016-06-08 14:37:15 -05:00
Paul E. Murphy 8938513484 Apply LIT(x) to floating point literals in libm-test.c
With the exception of the second argument of nexttoward,
any suffixes should be stripped from the test input, and
the macro LIT(x) should be applied to use the correct
suffix for the type being tested.

This adds a new argument type "j" to gen-test-libm.pl
to signify an argument to a test input which does not
require fixup.  The test cases of nexttoward have
been updated to use this new feature.

This applies post-processing to all of the test inputs
through gen-libm-test.pl to strip literal suffixes and
apply the LIT(x) macro, with one exception stated above.
This seems a bit cleaner than tossing the macro onto
everything, albeit slightly more obfuscated.
2016-06-08 14:28:25 -05:00
Joseph Myers 8fa8a330f9 Fix i386 atanhl (sNaN) (bug 20219).
The i386 version of atanhl returns sNaN for sNaN input.  This patch
fixes it to add NaN arguments to themselves so it returns qNaN in this
case.

Tested for x86_64 and x86.

	[BZ #20219]
	* sysdeps/i386/fpu/e_atanhl.S (__ieee754_atanhl): Add NaN argument
	to itself.
	* math/libm-test.inc (atanh_test_data): Add sNaN tests.
2016-06-07 23:08:32 +00:00
Joseph Myers c23805a95d Fix i386 asinhl (sNaN) (bug 20218).
The i386 version of asinhl returns sNaN (without raising any
exceptions) for sNaN input.  This patch fixes it to add non-finite
arguments to themselves, so that "invalid" is raised and qNaN
returned.

Tested for x86_64 and x86.

	[BZ #20218]
	* sysdeps/i386/fpu/s_asinhl.S (__asinhl): Add non-finite argument
	to itself.
	* math/libm-test.inc (asinh_test_data): Add sNaN tests.
2016-06-07 22:54:58 +00:00
Joseph Myers 3d8b06bc61 Fix dbl-64 asin (sNaN) (bug 20213).
The dbl-64 version of asin returns sNaN for sNaN arguments.  This
patch fixes it to add NaN arguments to themselves so that qNaN is
returned in this case.

Tested for x86_64 and x86.

	[BZ #20213]
	* sysdeps/ieee754/dbl-64/e_asin.c (__ieee754_asin): Add NaN
	argument to itself.
	* math/libm-test.inc (asin_test_data): Add sNaN tests.
2016-06-06 22:21:11 +00:00
Joseph Myers af0cfbaf1d Fix dbl-64 acos (sNaN) (bug 20212).
The dbl-64 version of acos returns sNaN for sNaN arguments.  This
patch fixes it to add NaN arguments to themselves so that qNaN is
returned in this case.

Tested for x86_64 and x86.

	[BZ #20212]
	* sysdeps/ieee754/dbl-64/e_asin.c (__ieee754_acos): Add NaN
	argument to itself.
	* math/libm-test.inc (acos_test_data): Add sNaN tests.
2016-06-06 22:10:11 +00:00
Joseph Myers 8cbd1453ec Fix x86/x86_64 nextafterl incrementing negative subnormals (bug 20205).
The x86 / x86_64 implementation of nextafterl (also used for
nexttowardl) produces incorrect results (NaNs) when negative
subnormals, the low 32 bits of whose mantissa are zero, are
incremented towards zero.  This patch fixes this by disabling the
logic to decrement the exponent in that case.

Tested for x86_64 and x86.

	[BZ #20205]
	* sysdeps/i386/fpu/s_nextafterl.c (__nextafterl): Do not adjust
	exponent when incrementing negative subnormal with low mantissa
	word zero.
	* math/libm-test.inc (nextafter_test_data) [TEST_COND_intel96]:
	Add another test.
2016-06-03 21:30:12 +00:00
Paul E. Murphy f64f68f53b Replace M_El with lit_e in libm-test.inc
This is useful in situations where the long double type is
less precise than the type under test.
2016-05-27 12:06:15 -05:00
Paul E. Murphy 9513192bc7 Replace M_PI_4l with lit_pi_4_d in libm-test.inc
This is useful in situations where the long double type is
less precise than the type under test.
2016-05-27 12:06:11 -05:00
Paul E. Murphy 9289b5553b Replace M_PIl with lit_pi in libm-test.inc
This is useful in situations where the long double type is
less precise than the type under test.
2016-05-27 12:06:08 -05:00
Paul E. Murphy 84ba459dcf Replace M_PI2l with lit_pi_2_d in libm-test.inc
This is useful in situations where the long double type is
less precise than the type under test.  This adds a new
wrapper macro LITM(x) to each type to append the proper
suffix onto macro constants found in math.h.
2016-05-27 12:03:33 -05:00
Paul E. Murphy 135d1c7f6a Refactor M_ macros defined in libm-test.inc
These are local to the test suite.  Rename them as a macro starting
with lit_pi and a series of postfix operations to give us a constant
starting with lit_pi.

The lit prefix is intended to enable easy substitutions via
gen-test-libm.pl if needed.
2016-05-27 12:02:34 -05:00
Joseph Myers d8728df430 Remove unused macros from libm-test.inc.
This patch removes various no-longer-used macros from libm-test.inc.
NO_TEST_INLINE_FLOAT, NO_TEST_INLINE_DOUBLE and M_PI_6l would have
been used before relevant tests were moved to auto-libm-test-in.
TEST_COND_x86_64 and TEST_COND_x86 were for tests in auto-libm-test-in
XFAILed for x86, and are no longer relevant now the bugs in question
have been fixed and the XFAILing removed (if future x86-specific
XFAILs become needed, they can always be added back).

Tested for x86_64 and x86.

	* math/libm-test.inc (NO_TEST_INLINE_FLOAT): Remove macro.
	(NO_TEST_INLINE_DOUBLE): Likewise.
	(TEST_COND_x86_64): Likewise.
	(TEST_COND_x86): Likewise.
	(M_PI_6l): Likewise.
2016-05-27 15:26:48 +00:00
Paul E. Murphy de628893f6 Refactor type specific macros using regexes
Replace most of the type specific macros  with the equivalent
type-generic macro using the following sed replacement command below:

sed -ri -e 's/defined TEST_FLOAT/TEST_COND_binary32/' \
        -e 's/ndef TEST_FLOAT/ !TEST_COND_binary32/'  \
        -e 's/def TEST_FLOAT/ TEST_COND_binary32/'    \
        -e 's/defined TEST_DOUBLE/TEST_COND_binary64/'\
        -e 's/ndef TEST_DOUBLE/ !TEST_COND_binary64/' \
        -e 's/def TEST_DOUBLE/ TEST_COND_binary64/'   \
        -e 's/defined TEST_LDOUBLE && //'             \
        -e 's/ifdef TEST_LDOUBLE/if MANT_DIG >= 64/'  \
        -e 's/defined TEST_LDOUBLE/MANT_DIG >= 64/'   \
        -e '/nexttoward_test_data\[\]/,/  };/!s/LDBL_(MIN_EXP|MAX_EXP|MANT_DIG)/\1/g' \
        libm-test.inc

With a little extra manual cleanup to simplify the following case:

#if MANT_DIG >= 64
# if MANT_DIG >= 64
...
# endif
...

Note, TEST_LDOUBLE checks are replaced by MANT_DIG >= 64 excepting
where another property of the type is being tested. And, the final
regex is intended to avoid replacing LDBL_ macro usage within the
nexttoward tests which explicitly take argument 2 as long double.
2016-05-27 09:57:30 -05:00
Paul E. Murphy 5f7b8f457f Begin refactor of libm-test.inc
Attempt to creatively redefine the macros
to choose tests based on the format being
tested, not the type.

Note, TS 18661 does not define any printf
modifiers, so we need to be a little more
verbose about constructing strings to
output.
2016-05-27 09:57:21 -05:00
Joseph Myers 960be82cc2 Add more sNaN tests to libm-test.inc.
This patch adds more tests of signaling NaN inputs to libm-test.inc.
These tests are for a subset of functions with a single floating-point
input where no failures appeared in x86_64 or x86 testing.  I intend
to investigate any failures of these new tests on some other
architectures before dealing with other functions.

Tested for x86_64 and x86.

	* math/libm-test.inc (acosh_test_data): Add sNaN tests.
	(atan_test_data): Likewise.
	(ceil_test_data): Likewise.
	(cos_test_data): Likewise.
	(cosh_test_data): Likewise.
	(erf_test_data): Likewise.
	(exp2_test_data): Likewise.
	(fabs_test_data): Likewise.
	(floor_test_data): Likewise.
	(ilogb_test_data): Likewise.
	(j0_test_data): Likewise.
	(j1_test_data): Likewise.
	(jn_test_data): Likewise.
	(lgamma_test_data): Likewise.
	(lrint_test_data): Likewise.
	(llrint_test_data): Likewise.
	(logb_test_data): Likewise.
	(lround_test_data): Likewise.
	(llround_test_data): Likewise.
	(nearbyint_test_data): Likewise.
	(rint_test_data): Likewise.
	(round_test_data): Likewise.
	(sin_test_data): Likewise.
	(sincos_test_data): Likewise.
	(sinh_test_data): Likewise.
	(sqrt_test_data): Likewise.
	(tan_test_data): Likewise.
	(tanh_test_data): Likewise.
	(tgamma_test_data): Likewise.
	(trunc_test_data): Likewise.
	(y0_test_data): Likewise.
	(y1_test_data): Likewise.
	(yn_test_data): Likewise.
2016-05-26 18:07:04 +00:00
Joseph Myers 262112840c Support sNaN testing in libm-test.inc.
This patch adds support in libm-test.inc for tests with signaling NaN
arguments.  gen-libm-test.pl is made to set a flag TEST_SNAN for such
tests, so that they can be disabled automatically when sNaN testing
isn't supported for a given type (at present, for float and double on
32-bit x86 because it's unpredictable when a value might be loaded
into a floating-point register and so automatically converted to long
double with sNaNs converted to quiet NaNs).  -fsignaling-nans is used
where needed.

Tests are added for classification macros, as a starting point; this
is deliberately more conservative than Thomas's patch
<https://sourceware.org/ml/libc-ports/2013-04/msg00008.html>, to allow
more tests to be added, and issues exposed fixed, bit by bit.

Tested for x86_64 and x86.

	* math/libm-test.inc: Update comment about NaN testing.
	(TEST_SNAN): New macro.
	(snan_value): Likewise.
	(enable_test): Disable tests of sNaNs when SNAN_TESTS fails.
	(fpclassify_test_data): Add sNaN tests.
	(isfinite_test_data): Likewise.
	(isinf_test_data): Likewise.
	(isnan_test_data): Likewise.
	(isnormal_test_data): Likewise.
	(issignaling_test_data): Likewise.
	(signbit_test_data): Likewise.
	* math/gen-libm-test.pl (%beautify): Add snan_value.
	(show_exceptions): Add argument $test_snan.
	(parse_args): Handle snan_value as non-finite.  Update call to
	show_exceptions.
	* math/Makefile (libm-test-no-inline-cflags): Add
	-fsignaling-nans.
2016-05-26 16:38:04 +00:00
Paul E. Murphy 7cfcb778c9 Fixup usage of MIN_EXP in libm-test.inc
Make MANT_DIG shadow the types *_MIN_EXP macro. Replace
calls sites with (MIN_EXP - 1), and simplify.
2016-05-24 15:37:49 -05:00
Paul E. Murphy 7e9ae8292f Fixup usage of MANT_DIG in libm-test.inc
Make MANT_DIG shadow the types *_MANT_DIG macro. Replace
calls sites with (MANT_DIG - 1), and simplify.
2016-05-24 15:35:39 -05:00
Joseph Myers 078d1cf8ac Do not raise "inexact" from generic round (bug 15479).
C99 and C11 allow but do not require ceil, floor, round and trunc to
raise the "inexact" exception for noninteger arguments.  TS 18661-1
requires that this exception not be raised by these functions.  This
aligns them with general IEEE semantics, where "inexact" is only
raised if the final step of rounding the infinite-precision result to
the result type is inexact; for these functions, the
infinite-precision integer result is always representable in the
result type, so "inexact" should never be raised.

The generic implementations of ceil, floor and round functions contain
code to force "inexact" to be raised.  This patch removes it for round
functions to align them with TS 18661-1 in this regard.  The tests
*are* updated by this patch; there are fewer architecture-specific
versions than for ceil and floor, and I fixed the powerpc ones some
time ago.  If any others still have the issue, as shown by tests for
round failing with spurious exceptions, they can be fixed separately
by architecture maintainers or others.

Tested for x86_64, x86 and mips64.

	[BZ #15479]
	* sysdeps/ieee754/dbl-64/s_round.c (huge): Remove variable.
	(__round): Do not force "inexact" exception.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_round.c (huge): Remove
	variable.
	(__round): Do not force "inexact" exception.
	* sysdeps/ieee754/flt-32/s_roundf.c (huge): Remove variable.
	(__roundf): Do not force "inexact" exception.
	* sysdeps/ieee754/ldbl-128/s_roundl.c (huge): Remove variable.
	(__roundl): Do not force "inexact" exception.
	* sysdeps/ieee754/ldbl-96/s_roundl.c (huge): Remove variable.
	(__roundl): Do not force "inexact" exception.
	* math/libm-test.inc (round_test_data): Do not allow spurious
	"inexact" exceptions.
2016-05-24 17:46:55 +00:00
Joseph Myers ffe9aaf2b9 Implement proper fmal for ldbl-128ibm (bug 13304).
ldbl-128ibm had an implementation of fmal that just did (x * y) + z in
most cases, with no attempt at actually being a fused operation.

This patch replaces it with a genuine fused operation.  It is not
necessarily correctly rounding, but should produce a result at least
as accurate as the long double arithmetic operations in libgcc, which
I think is all that can reasonably be expected for such a non-IEEE
format where arithmetic is approximate rather than rounded according
to any particular rule for determining the exact result.  Like the
libgcc arithmetic, it may produce spurious overflow and underflow
results, and it falls back to the libgcc multiplication in the case of
(finite, finite, zero).

This concludes the fixes for bug 13304; any subsequently found fma
issues should go in separate Bugzilla bugs.  Various other pieces of
bug 13304 were fixed in past releases over the past several years.

Tested for powerpc.

	[BZ #13304]
	* sysdeps/ieee754/ldbl-128ibm/s_fmal.c: Include <fenv.h>,
	<float.h>, <math_private.h> and <stdlib.h>.
	(add_split): New function.
	(mul_split): Likewise.
	(ext_val): New typedef.
	(store_ext_val): New function.
	(mul_ext_val): New function.
	(compare): New function.
	(add_split_ext): New function.
	(__fmal): After checking for Inf, NaN and zero, compute result as
	an exact sum of scaled double values in round-to-nearest before
	adding those up and adjusting for other rounding modes.
	* math/auto-libm-test-in: Remove xfail-rounding:ldbl-128ibm from
	tests of fma.
	* math/auto-libm-test-out: Regenerated.
2016-05-19 20:10:56 +00:00
Joseph Myers b3d7eaf10a Update libm-test.inc comment about NaN signs.
libm-test.inc has a comment about signs of NaNs not being tested.
This is out of date since:

commit ce66581742
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Sat Nov 16 12:48:35 2013 +0000

    Test signs of NaNs in libm-test.inc where appropriate.

This patch removes the inaccurate statement.

	* math/libm-test.inc: Update comment not to refer to signs of NaNs
	not being tested.
2016-05-18 21:57:25 +00:00
Andreas Schwab b4bcb3aec6 Register extra test objects
This makes sure that the extra test objects are compiled with the correct
MODULE_NAME and dependencies are tracked.
2016-04-13 17:07:13 +02:00
Joseph Myers c898991d8b Fix x86_64 / x86 powl inaccuracy for integer exponents (bug 19848).
Bug 19848 reports cases where powl on x86 / x86_64 has error
accumulation, for small integer exponents, larger than permitted by
glibc's accuracy goals, at least in some rounding modes.  This patch
further restricts the exponent range for which the
small-integer-exponent logic is used to limit the possible error
accumulation.

Tested for x86_64 and x86 and ulps updated accordingly.

	[BZ #19848]
	* sysdeps/i386/fpu/e_powl.S (p3): Rename to p2 and change value
	from 8 to 4.
	(__ieee754_powl): Compare integer exponent against 4 not 8.
	* sysdeps/x86_64/fpu/e_powl.S (p3): Rename to p2 and change value
	from 8 to 4.
	(__ieee754_powl): Compare integer exponent against 4 not 8.
	* math/auto-libm-test-in: Add more tests of pow.
	* math/auto-libm-test-out: Regenerated.
	* sysdeps/i386/i686/fpu/multiarch/libm-test-ulps: Update.
	* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.
2016-03-24 01:32:52 +00:00
Dylan Alex Simon f9378ac377 math: don't clobber old libm.so on install [BZ #19822]
When installing glibc (w/mathvec enabled) in-place on a system with
a glibc w/out mathvec enabled, the install will clobber the existing
libm.so (e.g., /lib64/libm-2.21.so) with a linker script.  This is
because libm.so is a symlink to libm.so.6 which is a symlink to the
final libm-2.21.so file.  When the makefile writes the linker script
directly to libm.so, it gets clobbered.

The simple patch below to math/Makefile fixes this.  It is based on
the nptl Makefile, which does exactly the same thing in a safer way.
2016-03-21 02:07:51 -04:00
Carlos O'Donell b4f518ecfa Fix building glibc master with NDEBUG and --with-cpu.
When building on i686, x86_64, and arm, and with NDEBUG, or --with-cpu
there are various variables and functions which are unused based on
these settings.

This patch marks all such variables with __attribute__((unused)) to
avoid the compiler warnings when building with the aformentioned
options.
2016-03-15 23:23:24 -04:00
Andreas Schwab 2beb1010e4 Fix compilation of test-signgam-* tests 2016-03-15 00:03:03 +01:00
Joseph Myers b55b28e657 Allow spurious underflow / inexact for ldbl-128ibm.
A large number of the test-ldouble failures seen for ldbl-128ibm are
spurious "underflow" and "inexact" exceptions.  These arise from such
exceptions in the underlying arithmetic; unlike other spurious
exceptions from that arithmetic, they do not in general relate to
cases where the returned result is also substantially inaccurate, are
not so readily avoidable by appropriately conditional libgcc patches,
and are widespread enough to be hard to handle through individual
XFAILing of the affected tests.

Thus, this patch documents relaxed accuracy goals for libm functions
for IBM long double and makes libm-test.inc reflect these spurious
exceptions in ldbl-128ibm arithmetic and always allow them in
ldbl-128ibm testing (while still not allowing these exceptions to be
missing where required to be present).  Tested for powerpc.

	* manual/math.texi (Errors in Math Functions): Document relaxed
	accuracy goals for IBM long double.
	* math/libm-test.inc (test_exceptions): Always allow spurious
	"underflow" and "inexact" exceptions for IBM long double.
2016-03-10 23:48:46 +00:00
Roland McGrath 0800411f9c Omit test-math-isinff when no C++ compiler. 2016-03-04 13:27:25 -08:00
Andreas Schwab 8dfdd0794a Don't use long double math functions if NO_LONG_DOUBLE 2016-02-24 11:59:42 +01:00
Joseph Myers 9120a57f48 Fix ldbl-128ibm remainderl, remquol equality tests (bug 19603).
The ldbl-128ibm implementations of remainderl and remquol have logic
resulting in incorrect tests for equality of the absolute values of
the arguments.  Equality is tested based on the integer
representations of the high and low parts, with the sign bit masked
off the high part - but when this changes the sign of the high part,
the sign of the low part needs to be changed as well, and failure to
do this means arguments are wrongly treated as equal when they are
not.

This patch fixes the logic to adjust signs of low parts as needed.
Tested for powerpc.

	[BZ #19603]
	* sysdeps/ieee754/ldbl-128ibm/e_remainderl.c
	(__ieee754_remainderl): Adjust sign of integer version of low part
	when taking absolute value of high part.
	* sysdeps/ieee754/ldbl-128ibm/s_remquol.c (__remquol): Likewise.
	* math/libm-test.inc (remainder_test_data): Add another test.
	(remquo_test_data): Likewise.
2016-02-19 00:55:46 +00:00
Carlos O'Donell 3c47c83a97 Ensure isinff, isinfl, isnanf, and isnanl are defined (Bug 19439)
In ICO C++11 mode ensure that isinff, isinfl, isnanf, and isnanl
are defined.  These functions were accidentally removed from the
header as part of commit d9b965fa56,
but being GNU extensions, they should have been left in place.
2016-02-14 20:09:52 -05:00
Joseph Myers 2e3d0de31f Fix ulps regeneration for *-finite tests.
On running tests after from-scratch ulps regeneration, I found that
some libm tests failed with ulps in excess of those recorded in the
from-scratch regeneration, which should never happen unless those ulps
exceed the limit on ulps that can go in libm-test-ulps files.

Failure: Test: atan2_upward (inf, -inf)
Result:
 is:          2.35619498e+00   0x1.2d97ccp+1
 should be:   2.35619450e+00   0x1.2d97c8p+1
 difference:  4.76837159e-07   0x1.000000p-21
 ulp       :  2.0000
 max.ulp   :  1.0000
Maximal error of `atan2_upward'
 is      : 2 ulp
 accepted: 1 ulp
Failure: Test: carg_upward (-inf + inf i)
Result:
 is:          2.35619498e+00   0x1.2d97ccp+1
 should be:   2.35619450e+00   0x1.2d97c8p+1
 difference:  4.76837159e-07   0x1.000000p-21
 ulp       :  2.0000
 max.ulp   :  1.0000
Maximal error of `carg_upward'
 is      : 2 ulp
 accepted: 1 ulp

The problem comes from the addition of tests for the finite-math-only
versions of libm functions.  Those tests share ulps with the default
function variants.  make regen-ulps runs the default tests before the
finite-math-only tests, concatenating the resulting ulps before
feeding them to gen-libm-test.pl to generate a new libm-test-ulps
file.  But gen-libm-test.pl always takes the last ulps value given for
any (function, type) pair.  So, if the largest ulps for a function
come from non-finite inputs, a from-scratch regeneration loses those
ulps.

This patch fixes gen-libm-test.pl, in the case where there are
multiple ulps values for a (function, type) pair - which can only
happen as part of a regeneration - to take the largest ulps value
rather than the last one.

Tested for ARM / MIPS / powerpc-nofpu.

	* math/gen-libm-test.pl (parse_ulps): Do not reduce
	already-recorded ulps.
	* sysdeps/arm/libm-test-ulps: Regenerated.
	* sysdeps/mips/mips32/libm-test-ulps: Likewise.
	* sysdeps/mips/mips64/libm-test-ulps: Likewise.
	* sysdeps/powerpc/nofpu/libm-test-ulps: Likewise.
2016-01-19 21:42:58 +00:00
Paul Pluzhnikov 8d079ae0cd [BZ #19451]
* math/Makefile (libm-vec-tests): Move libraries after wrappers.o to fix
"make check" link failure on Ubuntu.
2016-01-18 14:36:28 -08:00