Home | History | Annotate | only in /src/tests/lib/libm
History log of /src/tests/lib/libm
RevisionDateAuthorComments
 1.54 16-Sep-2025  nat Revert to previous as requested by Rin.

As I found out the hack only applies to libc/softfloat which has issues on
m68k.

The hack should not have been applied to all m68k configurations.
 1.53 11-Sep-2025  nat Opps...Fix build.
 1.52 11-Sep-2025  nat Fix segfaults of libm tests noticable on m68k.

Also document it in doc/HACKS.
 1.51 19-Sep-2024  gdt tests: Add test for remquo

This test currently fails, because remquo has bugs. (A bugfix will be
committed soon.) Test vectors derived from results from code by
Charles Karney in GeodesicLib/proj, and manually inspected.
 1.50 09-Sep-2024  riastradh math.h: Add math_errhandling, MATH_ERRNO, MATH_ERREXCEPT.

XXX Should maybe put a __math_errhandling in machine/math.h, but only
VAX uses MATH_ERRNO and that's not likely to change any time soon, so
this will serve for now with less churn.

PR standards/56234: missing C99 frobs in <math.h>
 1.49 05-May-2024  riastradh branches: 1.49.2;
tests/lib/libm: Test nextafter/nexttoward and variants.

The tests are fairly trivial but should work without any conditionals
about floating-point formats.
 1.48 27-Aug-2022  christos branches: 1.48.2;
Add sincos{,f,l} from FreeBSD
 1.47 21-Jun-2020  lukem fix build of t_cabsl from t_cabsl.cxx

t_cabsl source is in t_cabsl.cxx not t_cabsl.cc - the latter
is what bsd.tests.mk defaults to.

This only broke after my commit of share/mk/bsd.dep.mk rev 1.85
but I don't know why it didn't cause a problem previously.
 1.46 26-Apr-2019  maya branches: 1.46.2;
Add a test case for signbit.
(paranoia prior to a libm change)
 1.45 07-Nov-2018  riastradh Build libm tests with -fno-builtin.

This way they test libm, not whatever the compiler does.

We should _also_ have automatic integration tests for what the
compiler does, as a separate thing.
 1.44 20-Jun-2018  maya branches: 1.44.2;
Add test case for PR lib/50646.

Make sure that cabsl (aka __c99_cabsl) is usable from C++.
 1.43 04-Jun-2018  maya Blindly add __TEST_FENV in the hope of fixing the vax build.

(So we can include fenv.h, and then not use it - we ifdef vax out
for OS-portability reasons.)
 1.42 20-Dec-2016  maya branches: 1.42.12;
define __TEST_FENV in the makefile for t_fe_round
should fix vax build (it doesn't have fenv.h)
 1.41 19-Dec-2016  maya add test for fesetround/fegetround that uses lrint (and tests it a bunch).
It doesn't fail on amd64.
 1.40 31-Aug-2016  maya Add failing test for casinh
 1.39 23-Aug-2016  christos portability fixes
 1.38 22-Aug-2016  maya add failing test for PR lib/51427
ilogb(INFINITY)=-INT_MAX, it should be INT_MAX

while here, test raised exceptions, other values.

XXX some platforms don't have exceptions
 1.37 24-Jan-2016  gson branches: 1.37.2;
Add some tests of hypot() and hypotf()
 1.36 22-Dec-2015  christos add __TEST_FENV
 1.35 22-Dec-2015  christos put have fenv stuff elsewhere.
 1.34 22-Dec-2015  martin Sync list of fenv enabled architectures again (PR 48633), this time for mips
addition.
 1.33 21-Dec-2015  martin While PR 48633 is not properly fixed, keep the additional lists of
fenv-enabled architectures in sync.
 1.32 20-Jan-2015  snj Remove stale comment about ARM fenv support.
 1.31 03-Jan-2015  gson Mark the lib/libm/t_fmod test as an expected failure under QEMU,
with a reference to PR misc/44767.
 1.30 27-Dec-2014  martin Enable fenv.h on arm again
 1.29 27-Dec-2014  martin fenv(3) support for hppa
 1.28 22-Dec-2014  martin Disabel fenv tests for arm, the implementation is incomplete.
 1.27 21-Dec-2014  martin Add a test program for basic fenv.h rounding mode/exception mask testing.
 1.26 10-Aug-2014  martin branches: 1.26.2;
Use the same condition for HAVE_FENV
 1.25 16-Jun-2014  joerg Add modfl(3). From FreeBSD.
 1.24 18-May-2014  martin Re-enable alpha IEEE compiler options
 1.23 05-May-2014  martin Comment out the ieee fp flags for alpha for now - something (tm) is not
working right, see PR port-alpha/48782.
 1.22 28-Apr-2014  martin Tune COPTS for alpha
 1.21 03-Mar-2014  martin branches: 1.21.2;
Define HAVE_FENV_H on architectures that support it.
What a mess, we need a central place for this!
 1.20 12-Nov-2013  joerg Initial version of fmodl from FreeBSD.
Basic test case for the fmod family.
 1.19 11-Nov-2013  joerg NetBSD 6.99.26: Switch i386 and amd64 to the x87 default control word
as initial value for new processes. This means that long double
computations get the expected 63bit mantissa. Binaries tagged as
compiled for 6.99.25 and older get the old value.

Add a simple test case to ensure that double and long double computation
are working correctly.
 1.18 13-Apr-2012  njoly branches: 1.18.2;
Do not re-add -mieee option on alpha, it's already set by default.
 1.17 16-Oct-2011  jruoho branches: 1.17.2;
Remove 't_rint' as it was committed accidentally.
 1.16 16-Oct-2011  jruoho As couple of checks fails on i386/qemu, reduce tolerance.
 1.15 16-Oct-2011  jruoho Add t_sqrt and t_cbrt.
 1.14 16-Oct-2011  jruoho Basic IEEE tests for the hyperbolic sine and cosine.
 1.13 18-Sep-2011  jruoho IEEE checks for the exponential family.
 1.12 17-Sep-2011  jruoho IEEE checks for the arcus functions.
 1.11 17-Sep-2011  jruoho Few tests for the error functions.
 1.10 17-Sep-2011  jruoho IEEE corner case tests for the pow(3) family (incl. PR lib/45372).
 1.9 14-Sep-2011  jruoho Some tests for sine, cosine, and tangent.
 1.8 12-Sep-2011  jruoho Merge 't_floor' to 't_ceil', and simplify.
 1.7 12-Sep-2011  jruoho Start systematic testing of libm(3) by first evaluating the corner cases
(NaN, +0.0, -0.0, +Inf, -Inf) for the ldexp(3) and scalbn(3) families.
 1.6 11-Apr-2011  martin Try to generate infinite values in all available floating point formats
on the FPU and check isinf() and fpclassify() results. This is
different from the libc internal consistency checks testing PR
lib/33262.
 1.5 10-Apr-2011  jruoho Add a test case for PR lib/41931 reported by he@. It was verified that these
fail on NetBSD 5.99.48 amd64 but pass on amd64 Linux (glibc 2.7).
 1.4 08-Apr-2011  jruoho Move the round(3) checks from 't_libm' to their own 't_round'
for consistency. Add -Wfloat-equal and fix comparisons.
 1.3 06-Apr-2011  jruoho A test case for PR lib/44057.
 1.2 24-Mar-2011  jruoho Add dummy test cases for ceil(3) and floor(3). It is expected that at least
one of these will fail on guest x86_64 NetBSD under Qemu. Thanks to pgoyette@
for checking the broken floor(16.999999...) = 17.
 1.1 20-Dec-2010  pgoyette Move the only regress/lib/libm test to the new atf format
 1.17.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.2.1 17-Apr-2012  yamt sync with head
 1.18.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.2.1 10-Aug-2014  tls Rebase.
 1.26.2.2 20-Jan-2015  snj Pull up following revision(s) (requested by martin in ticket #416):
distrib/sets/lists/comp/md.hppa: revision 1.3
include/fenv.h: revision 1.13 via patch
lib/libm/Makefile: revision 1.168
lib/libm/arch/hppa/fenv.c: revisions 1.1, 1.2
sys/arch/hppa/include/Makefile: revision 1.12
sys/arch/hppa/include/fenv.h: revisions 1.1, 1.2
sys/arch/hppa/include/ieeefp.h: revisions 1.5-1.7
tests/lib/libm/Makefile: revision 1.29 via patch
fenv(3) support for hppa
--
use unsigned over uint32_t so that this file works without stdint.h
being included before hand.
fixes mknative-gcc problems, and likely others.
--
Properly separate fenv.h and ieeefp.h by moving all fenv defines
over to the former.
Now that they are decoupled, make rounding modes match the hardware bits.
--
Simplify, now that rounding mode defines match the hardware bits.
 1.26.2.1 12-Jan-2015  snj Pull up following revision(s) (requested by gson in ticket #413):
tests/lib/libm/Makefile: revision 1.31
tests/lib/libm/t_fmod.c: revision 1.3
Mark the lib/libm/t_fmod test as an expected failure under QEMU,
with a reference to PR misc/44767.
 1.37.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.42.12.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.42.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.44.2.1 10-Jun-2019  christos Sync with HEAD
 1.46.2.1 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #963):

tests/lib/libm/Makefile: revision 1.49
distrib/sets/lists/tests/mi: revision 1.1315
tests/lib/libm/t_next.c: revision 1.1
tests/lib/libm/t_next.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.435
tests/lib/libm/t_next.c: revision 1.3
tests/lib/libm/t_next.c: revision 1.4
tests/lib/libm/t_next.c: revision 1.5
tests/lib/libm/t_next.c: revision 1.6
lib/libm/src/s_nexttoward.c: revision 1.3
(all via patch)

tests/lib/libm: Test nextafter/nexttoward and variants.

The tests are fairly trivial but should work without any conditionals
about floating-point formats.
tests/lib/libm/t_next: Disable this test on VAX.

But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.

tests/lib/libm/t_next: Fix stub on VAX.
Tested building the wrong tree, oops.

tests/lib/libm/t_next: Expand substantially.

This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
tests/lib/libm/t_next: nexttoward works if it's just nextafter.

It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
nexttoward(3): Fix high-word test on small positive subnormals.

By this point in the logic, x can't be zero, so it's either positive
or negative.

The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
 1.48.2.3 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #963):

tests/lib/libm/Makefile: revision 1.49
distrib/sets/lists/tests/mi: revision 1.1315
tests/lib/libm/t_next.c: revision 1.1
tests/lib/libm/t_next.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.435
tests/lib/libm/t_next.c: revision 1.3
tests/lib/libm/t_next.c: revision 1.4
tests/lib/libm/t_next.c: revision 1.5
tests/lib/libm/t_next.c: revision 1.6
lib/libm/src/s_nexttoward.c: revision 1.3

tests/lib/libm: Test nextafter/nexttoward and variants.

The tests are fairly trivial but should work without any conditionals
about floating-point formats.
tests/lib/libm/t_next: Disable this test on VAX.

But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.

tests/lib/libm/t_next: Fix stub on VAX.
Tested building the wrong tree, oops.

tests/lib/libm/t_next: Expand substantially.

This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
tests/lib/libm/t_next: nexttoward works if it's just nextafter.

It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
nexttoward(3): Fix high-word test on small positive subnormals.

By this point in the logic, x can't be zero, so it's either positive
or negative.

The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
 1.48.2.2 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #950):

include/math.h: revision 1.71
include/math.h: revision 1.72
distrib/sets/lists/debug/mi: revision 1.448
tests/lib/libm/t_errhandling.c: revision 1.1
tests/lib/libm/t_errhandling.c: revision 1.2
tests/lib/libm/t_errhandling.c: revision 1.3
distrib/sets/lists/tests/mi: revision 1.1337
tests/lib/libm/Makefile: revision 1.50

math.h: Define FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL.

These are not strictly necessary to define, really, so we haven't
exactly been nonconformant. But they tell programs when they can
enable fast paths by using the fma(3) family of functions.

PR standards/56234: missing C99 frobs in <math.h>

math.h: Add math_errhandling, MATH_ERRNO, MATH_ERREXCEPT.
XXX Should maybe put a __math_errhandling in machine/math.h, but only
VAX uses MATH_ERRNO and that's not likely to change any time soon, so
this will serve for now with less churn.
PR standards/56234: missing C99 frobs in <math.h>

math.h: Add missing file for math_errhandling test.
PR standards/56234: missing C99 frobs in <math.h>

Add __TEST_FENV define to fix vax build

libm/t_errhandling.c: Put __TEST_FENV before any #includes.

This pattern avoids any potential problem with transitive inclusions
of fenv.h. (No change here because nothing else this file includes
transitively pulls in fenv.h, but being in the habit of doing it this
way avoids a class of problems.)

PR standards/56234: missing C99 frobs in <math.h>
 1.48.2.1 02-Oct-2024  martin Pull up following revision(s) (requested by gdt in ticket #912):

distrib/sets/lists/debug/mi: revision 1.449
lib/libm/src/s_remquo.c: revision 1.3
lib/libm/src/s_remquo.c: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1339
tests/lib/libm/t_remquo.c: revision 1.1
tests/lib/libm/t_remquo.c: revision 1.2
tests/lib/libm/Makefile: revision 1.51

tests: Add test for remquo

This test currently fails, because remquo has bugs. (A bugfix will be
committed soon.) Test vectors derived from results from code by
Charles Karney in GeodesicLib/proj, and manually inspected.

t_remquo: Work around missing remquo(3) for vax
Part of PR port-vax/57881

libm/remquo: Fix bug where wrong quotient was returned

Fix taken from FreeBSD:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=166463
https://cgit.freebsd.org/src/commit/lib/msun/src/s_remquo.c?id=1cbd288942b08217e99bf889e0967895d53af00c

FreeBSD commit message:
Fix a bug in remquo{,f,l}, in which the quotient didn't always have the
correct sign when the remainder was 0.
Fix a separate bug in remquo alone, in which the remainder and
quotient were both off by a bit in certain cases involving subnormal
remainders.
The bugs affected all platforms except amd64 and i386, on which the
routines are implemented in assembly.

(On NetBSD, this bug manifests on amd64.)

libm/remquo: Fix bug where remquo returned wrong sign of quo
ISO C requires that quo be congruent to the quotient mod 2^k and have
a particular sign. The current code can return 0 when it should be
negative.
Because the code chooses k=31 (for the requirement of congruence
modulo 2^k), the only value available (in ILP32 or LP64) that is
negative and congruent to 0 is 0x80000000. In the specific case of
wanting "-0", return 0x80000000.
Resolves t_remquo test failure.
 1.49.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.10 05-Mar-2014  dsl branches: 1.10.24; 1.10.26;
Fix some typos.
Make the infinity and nan constants 'double' not 'long double'.
 1.9 05-Mar-2014  dsl Move the #defines that simplified the test definitions and checks
into a separate header than can be used by the other libm tests.
Make the subtest index 'unsigned int' so that simple constants (eg 0)
print correctly.
 1.8 03-Mar-2014  dsl Remove the print of the rounding mode.
It was added in case it was non-zero - which it isn't.
It still isn't clear why acos(-1) gives the wrong result on some amd64
systems.
 1.7 03-Mar-2014  martin Fix build for platforms w/o fenv.h.
Remove some bogus #ifdef __vax__ (and add a few, hopefully non-bogus,
new ones).
 1.6 02-Mar-2014  dsl Include the subtest number in any error output.
Also temporarily print the rounding mode.
I think that acos(-1) is ending up with the wrong sign because the test
is being run with 'round towards -ve infinity' set.
I think it getting set somewhere and causing this test to fail.
The acos() code probably needs fixing - it shouldn't depend on the
round mode like this. But first I want to know if this if the error.
 1.5 01-Mar-2014  dsl Some of the acos() tests seem to fail on some systems.
Sorting out why isn't helped by the tests not reporting the erronous value.
Change the 'boilerplate' pattern used so that all the values are output.
Reduce the amount of faffy red tape as well.
Some of these reductions could be shared with other libm tests, but for
the moment they are defined in this file.
All these tests pass on my amd64 system, and when I run amd64 qemu.
 1.4 09-Apr-2013  isaki Use a pre-calculated value as expected result, instead of
comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
 1.3 23-Mar-2012  matt branches: 1.3.2;
If one of the tests with eps fails, print the failing eps.
 1.2 18-Sep-2011  jruoho branches: 1.2.2;
Reduce tolerance to see whether still acosf(cosf(x)) != x on i386/qemu.
 1.1 17-Sep-2011  jruoho IEEE checks for the arcus functions.
 1.2.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.2.1 23-Jun-2013  tls resync from head
 1.10.26.1 10-Jun-2019  christos Sync with HEAD
 1.10.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.5 11-May-2024  riastradh tests/lib/libm/t_asin: Cite PR lib/58246.
 1.4 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.3 03-Mar-2014  martin branches: 1.3.24; 1.3.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.2 09-Apr-2013  isaki Use a pre-calculated value as expected result, instead of
comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
 1.1 17-Sep-2011  jruoho branches: 1.1.2; 1.1.8;
IEEE checks for the arcus functions.
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 23-Jun-2013  tls resync from head
 1.1.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.26.1 10-Jun-2019  christos Sync with HEAD
 1.3.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.15 17-Mar-2014  martin Handle VAX
 1.14 08-Mar-2014  martin no NaN tests for vax
 1.13 07-Mar-2014  martin Vax does not do +/- INF.
 1.12 05-Mar-2014  dsl A couple of the atan tests are randomly failing.
Print the incorrect value.
 1.11 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.10 27-Feb-2014  joerg Avoid promotion in subexpressions.
 1.9 14-Jun-2013  isaki Remove header files which became unnecessary in 1.7.
 1.8 09-Apr-2013  isaki Use a pre-calculated value as expected result, instead of
comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
 1.7 21-Mar-2013  isaki Fix and revive test of atan_inf_neg, atan_inf_pos and atan_tan on i386.
PR port-i386/46108.
The machine epsilon 1.0e-40 is too severe and nonsense for double
because DBL_EPSILON is about 2.2e-16 . I think that 1.0e-15 is
enough good, in this case.
XXX However, test of atan_tan should be replaced for other reasons.
 1.6 11-Mar-2012  jruoho branches: 1.6.2;
And finally, fix boolean logic in the previous.
 1.5 11-Mar-2012  jruoho Fix previous: curiously enough, i386/qemu is not affected, so use the
"system(3) hack" to identify Qemu.
 1.4 10-Mar-2012  jruoho Point to PR port-i386/46108 when failing on i386.
 1.3 28-Feb-2012  pgoyette Remove an escape sequence that was introduced by accident.
 1.2 28-Feb-2012  jruoho Fix wrong type.
 1.1 17-Sep-2011  jruoho branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10;
IEEE checks for the arcus functions.
 1.1.10.1 23-Jun-2013  bouyer Pull up following revision(s) (requested by isaki in ticket #903):
tests/lib/libm/t_atan.c: revisions 1.4 - 1.7, 1.9 via patch
Fix and revive test of atan_inf_neg, atan_inf_pos and atan_tan on i386.
PR port-i386/46108.
The machine epsilon 1.0e-40 is too severe and nonsense for double
because DBL_EPSILON is about 2.2e-16 . I think that 1.0e-15 is
enough good, in this case.
XXX However, test of atan_tan should be replaced for other reasons.
Remove header files which became unnecessary in 1.7.
 1.1.8.1 23-Jun-2013  bouyer Pull up following revision(s) (requested by isaki in ticket #903):
tests/lib/libm/t_atan.c: revisions 1.4 - 1.7, 1.9 via patch
Fix and revive test of atan_inf_neg, atan_inf_pos and atan_tan on i386.
PR port-i386/46108.
The machine epsilon 1.0e-40 is too severe and nonsense for double
because DBL_EPSILON is about 2.2e-16 . I think that 1.0e-15 is
enough good, in this case.
XXX However, test of atan_tan should be replaced for other reasons.
Remove header files which became unnecessary in 1.7.
 1.1.4.1 23-Jun-2013  bouyer Pull up following revision(s) (requested by isaki in ticket #903):
tests/lib/libm/t_atan.c: revisions 1.4 - 1.7, 1.9 via patch
Fix and revive test of atan_inf_neg, atan_inf_pos and atan_tan on i386.
PR port-i386/46108.
The machine epsilon 1.0e-40 is too severe and nonsense for double
because DBL_EPSILON is about 2.2e-16 . I think that 1.0e-15 is
enough good, in this case.
XXX However, test of atan_tan should be replaced for other reasons.
Remove header files which became unnecessary in 1.7.
 1.1.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.6.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.2.1 23-Jun-2013  tls resync from head
 1.2 06-May-2024  riastradh tests/lib/libm/t_bit: Expand and tidy.

1. Instead of calling out VAX by name, use #ifdef NAN.

2. Verify signbit works on long double on all architectures, not just
those with __HAVE_LONG_DOUBLE which means long double is _larger_
than double.

3. Minor formatting tidying.
 1.1 26-Apr-2019  maya branches: 1.1.2;
Add a test case for signbit.
(paranoia prior to a libm change)
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Apr-2019  christos file t_bit.c was added on branch phil-wifi on 2019-06-10 22:10:07 +0000
 1.2 06-May-2024  riastradh tests/lib/libm/t_cabsl: Nix __HAVE_LONG_DOUBLE conditionals.

__HAVE_LONG_DOUBLE just means long double is different from double.
This test should always pass on all ports, even if long double is the
same as double; it doesn't test any additional precision.
 1.1 20-Jun-2018  maya branches: 1.1.2;
Add test case for PR lib/50646.

Make sure that cabsl (aka __c99_cabsl) is usable from C++.
 1.1.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.1.2.1 20-Jun-2018  pgoyette file t_cabsl.cxx was added on branch pgoyette-compat on 2018-06-25 07:26:09 +0000
 1.2 20-Sep-2016  christos print what went wrong.
 1.1 31-Aug-2016  maya branches: 1.1.2;
Add failing test for casinh
 1.1.2.3 04-Nov-2016  pgoyette Sync with HEAD
 1.1.2.2 14-Sep-2016  pgoyette Sync with HEAD
 1.1.2.1 31-Aug-2016  pgoyette file t_casinh.c was added on branch pgoyette-localcount on 2016-09-14 03:04:19 +0000
 1.6 03-Apr-2024  christos fix the cbrtl/powl test
 1.5 15-Nov-2018  riastradh cbrtl_powl is xfail only if long double has more bits than double.
 1.4 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.3 03-Mar-2014  martin branches: 1.3.24; 1.3.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.2 19-Nov-2013  joerg Add cbrtl(3) and sqrtl(3), from FreeBSD.
 1.1 16-Oct-2011  jruoho branches: 1.1.2; 1.1.8;
Basic checks for the root functions.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.26.1 10-Jun-2019  christos Sync with HEAD
 1.3.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.10 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.9 13-Nov-2013  joerg Add FreeBSD's truncl and minimal testing.
 1.8 11-Nov-2013  joerg Add initial version of ceill, floorl and roundl from FreeBSD.
 1.7 17-Sep-2011  jruoho branches: 1.7.2; 1.7.8;
Add more cases.
 1.6 12-Sep-2011  jruoho Fix typo.
 1.5 12-Sep-2011  jruoho Merge 't_floor' to 't_ceil', and simplify.
 1.4 04-Jul-2011  mrg XXX: ugly hack to make these valid for vax fp.
XXX: could consolidate some of this into a common header, but i'll
leave that clean up for another time.
 1.3 25-Mar-2011  jruoho Do not skip the QEMU bugs but instead mark these as expected failures.
 1.2 25-Mar-2011  jruoho Bluntly skip the tests that fail under QEMU. XXX: system(3) is used for this?

wnCVS: ----------------------------------------------------------------------
 1.1 24-Mar-2011  jruoho Add dummy test cases for ceil(3) and floor(3). It is expected that at least
one of these will fail on guest x86_64 NetBSD under Qemu. Thanks to pgoyette@
for checking the broken floor(16.999999...) = 17.
 1.7.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12 09-Jun-2024  riastradh tests/lib/libm: Fix various xfails related to PR lib/45362.

Writing

if (condition) {
atf_tc_expect_fail(...);
atf_tc_fail(...);
}

in order to paper over a bug in qemu renders the test nearly useless
because it will never actually fail in the event that something
unexpected is broken.

atf_tc_expect_fail only makes senes _before_ doing the test. If we
want to paper over a bug in qemu, we can do:

if (isQEMU)
atf_tc_expect_fail("qemu is broken, PR lib/...");
ATF_CHECK(condition);

That way, we are still doing the test in non-qemu circumstances, and
if the qemu bug is fixed the test will give the feedback of an
unexpected pass.

While here: Use `volatile double x = ...' as input so the compiler
doesn't optimize calls like sin(x) away at build-time, and print the
bad values with ATF_CHECK_MSG on failure in case anything goes wrong.
 1.11 06-May-2024  riastradh tests/lib/libm/t_cos: Fix comment about necessity of volatile.
 1.10 06-May-2024  riastradh tests/lib/libm/t_cos: Nix __HAVE_LONG_DOUBLE.

cosl should always be defined even on architectures where long double
is the same as double so the confusingly named __HAVE_LONG_DOUBLE is
not defined.
 1.9 27-May-2019  maya on i386 with FLT_EVAL_METHOD=2, the computation inside cosf was done in
binary80 arithmetic and never rounded to binary32 at the end, so it
appeared farther from the correctly rounded result in binary32 than expected.

Force binary32 using volatile float.

PR lib/54232: lib/libm/t_cos:cosf_angles regression on i386

From Riastradh.
 1.8 25-Apr-2019  maya Expand to cover long double somewhat.

The given data is for double, so use DBL_EPSILON and don't expect better
results.
 1.7 10-Nov-2018  riastradh Print the input to cosf on failure too.
 1.6 07-Nov-2018  riastradh Disable x87 implementations of sin, cos, tan.

The x87 hardware uses a bad approximation to pi for argument
reduction, and consequently yields bad answers for inputs near pi or
pi/2.

Tweak one tanf test whose doubly rounded output is a little too far
from the correct answer on the doubly rounded input.
 1.5 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.4 03-Mar-2014  martin branches: 1.4.24; 1.4.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.3 14-Sep-2011  jruoho branches: 1.3.2; 1.3.8;
Additions to PR lib/45362: the float variants cosf(3), sinf(3), and tanf(3)
do not detect NaN for positive and negative infinity on i386 (qemu).
 1.2 14-Sep-2011  jruoho Use fabsf(3) when appropriate.
 1.1 14-Sep-2011  jruoho Some tests for sine, cosine, and tangent.
 1.3.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.26.1 10-Jun-2019  christos Sync with HEAD
 1.4.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.7 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.6 03-Mar-2014  martin branches: 1.6.24; 1.6.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.5 09-Apr-2013  isaki Use a pre-calculated value as expected result, instead of
comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
 1.4 18-Oct-2011  jruoho branches: 1.4.2; 1.4.8;
Reduce tolerance even more.
 1.3 18-Oct-2011  jruoho Adjust and add some printfs.
 1.2 16-Oct-2011  jruoho As couple of checks fails on i386/qemu, reduce tolerance.
 1.1 16-Oct-2011  jruoho Basic IEEE tests for the hyperbolic sine and cosine.
 1.4.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 23-Jun-2013  tls resync from head
 1.4.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.26.1 10-Jun-2019  christos Sync with HEAD
 1.6.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.2 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.1 17-Sep-2011  jruoho branches: 1.1.2; 1.1.8;
Few tests for the error functions.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3 10-Sep-2024  riastradh branches: 1.3.2; 1.3.6;
libm/t_errhandling.c: Put __TEST_FENV before any #includes.

This pattern avoids any potential problem with transitive inclusions
of fenv.h. (No change here because nothing else this file includes
transitively pulls in fenv.h, but being in the habit of doing it this
way avoids a class of problems.)

PR standards/56234: missing C99 frobs in <math.h>
 1.2 09-Sep-2024  jakllsch Add __TEST_FENV define to fix vax build
 1.1 09-Sep-2024  riastradh math.h: Add missing file for math_errhandling test.

PR standards/56234: missing C99 frobs in <math.h>
 1.3.6.2 02-Aug-2025  perseant Sync with HEAD
 1.3.6.1 10-Sep-2024  perseant file t_errhandling.c was added on branch perseant-exfatfs on 2025-08-02 05:58:08 +0000
 1.3.2.2 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #950):

include/math.h: revision 1.71
include/math.h: revision 1.72
distrib/sets/lists/debug/mi: revision 1.448
tests/lib/libm/t_errhandling.c: revision 1.1
tests/lib/libm/t_errhandling.c: revision 1.2
tests/lib/libm/t_errhandling.c: revision 1.3
distrib/sets/lists/tests/mi: revision 1.1337
tests/lib/libm/Makefile: revision 1.50

math.h: Define FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL.

These are not strictly necessary to define, really, so we haven't
exactly been nonconformant. But they tell programs when they can
enable fast paths by using the fma(3) family of functions.

PR standards/56234: missing C99 frobs in <math.h>

math.h: Add math_errhandling, MATH_ERRNO, MATH_ERREXCEPT.
XXX Should maybe put a __math_errhandling in machine/math.h, but only
VAX uses MATH_ERRNO and that's not likely to change any time soon, so
this will serve for now with less churn.
PR standards/56234: missing C99 frobs in <math.h>

math.h: Add missing file for math_errhandling test.
PR standards/56234: missing C99 frobs in <math.h>

Add __TEST_FENV define to fix vax build

libm/t_errhandling.c: Put __TEST_FENV before any #includes.

This pattern avoids any potential problem with transitive inclusions
of fenv.h. (No change here because nothing else this file includes
transitively pulls in fenv.h, but being in the habit of doing it this
way avoids a class of problems.)

PR standards/56234: missing C99 frobs in <math.h>
 1.3.2.1 10-Sep-2024  martin file t_errhandling.c was added on branch netbsd-10 on 2024-10-11 19:01:12 +0000
 1.9 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.8 07-Oct-2014  gson branches: 1.8.14; 1.8.16;
In the exp2_values test case, provide separate expected return values
for the float case, reflecting the actual exp2f() argument value after
rounding to float precision. Fixes PR lib/49256. Thanks to Makoto
Kamada and Tetsuya Isaki for the analysis.
 1.7 17-Mar-2014  martin branches: 1.7.4;
Handle VAX
 1.6 16-Mar-2014  dsl Add a lot more tests for exp2() and exp2f().
exp2f(7.7) and exp2f(8.8) seem too far from their expected values
(especially the latter).
exp2(-1023) and below are badly broken.
 1.5 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.4 27-Feb-2014  joerg Avoid promotion in subexpressions.
 1.3 09-Apr-2013  isaki Tune the epsilon about each value for exp{,f}_product.
 1.2 30-May-2012  jruoho branches: 1.2.2;
Add patch from Tetsuya Isaki in PR lib/46433.
 1.1 18-Sep-2011  jruoho branches: 1.1.2;
IEEE checks for the exponential family.
 1.1.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.2.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.1 23-Jun-2013  tls resync from head
 1.7.4.1 07-Dec-2014  martin Pull up following revision(s) (requested by gson in ticket #296):
tests/lib/libm/t_exp.c: revision 1.8
In the exp2_values test case, provide separate expected return values
for the float case, reflecting the actual exp2f() argument value after
rounding to float precision. Fixes PR lib/49256. Thanks to Makoto
Kamada and Tetsuya Isaki for the analysis.
 1.8.16.1 10-Jun-2019  christos Sync with HEAD
 1.8.14.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.21 17-Apr-2025  riastradh t_fe_round: Mark xfail on sparc64.

PR port-sparc64/59310: t_fe_round:fe_nearbyint_rint tests are failing
 1.20 15-May-2024  riastradh branches: 1.20.2;
modfl(3): Fix conversion from FreeBSD.

LDBL_MANL_SIZE is spelled EXT_FRACLBITS -- and not EXT_FRACHBITS.

PR lib/58237: modfl returns wrong answers on ld128 architectures
 1.19 09-May-2024  riastradh tests/lib/libm/t_fe_round.c: Tidy.

nextafter/nexttoward tests didn't make much sense, and are now
supplanted by t_next.

PR misc/58054
 1.18 08-May-2024  riastradh tests/lib/libm/t_fe_round: xfail for modfl uses.

PR lib/58237: modfl returns wrong answers on ld128 architectures
 1.17 05-May-2024  riastradh tests/lib/libm/t_fe_round.c: Work around likely ia64 bug in gcc.
 1.16 03-May-2024  riastradh tests/lib/libm/t_fe_round.c: Expand nearbyint/rint tests.

PR lib/58054
 1.15 02-May-2024  riastradh tests/lib/libm/t_fe_round: Fix a missed cast.

Need long long or intmax_t, not long, on LP32.

PR lib/58054
 1.14 02-May-2024  riastradh tests/lib/libm/t_fe_round: Tidy up nearbyintl, sync nearbyint test.

PR lib/58054
 1.13 02-May-2024  riastradh tests/lib/libm/t_fe_round.c: Simplify previous.

There is never any need to write casts to type T in integer constant
initializers for type T.

PR lib/58054
 1.12 02-May-2024  kre Use intmax_t instead of long int when trying to represent very large
integers (10^50 or so), so we don't exceed the capacity of systems where
long int is only 32 bits.

Hopefully will unbreak the i386 build, perhaps others.
 1.11 02-May-2024  riastradh tests/lib/libm/t_fe_round: Test nearbyintl.

This uses inputs that can't be distinguished with only 53 bits of
precision, so it should work in essentially all long double formats
to detect when nearbyintl is incorrectly implemented in terms of
nearbyint.

PR lib/58054
 1.10 02-May-2024  riastradh tests/lib/libm/t_fe_round: Tidy up nearbyint test.

Prompted by PR lib/58054.
 1.9 21-Aug-2017  christos don't skip nexttoward for aarch64 and mips64
 1.8 20-Aug-2017  christos fix build (missing nexttoward on mips64 and aarch64)
 1.7 17-Aug-2017  he Add test cases for nextafter() and nexttoward(). At the moment no
corner cases are tested, and the test cases are little more than a
verification that the functions are present in the implementation.
 1.6 11-Aug-2017  he Re-enable the test for nearbyint(), now that all ports (save vax,
which has a separate #if section here) should have nearbyint().
 1.5 25-Jul-2017  uwe Revert previous as it breaks at least sparc and hpcsh builds.
nearbyint() is not included in libm on all platforms.
 1.4 24-Jul-2017  he Add a test checking nearbyint(), using the same table as used by
the existing lrint() test.
 1.3 24-Jul-2017  he Swap around the two last args to the check for expected fegetround(),
so the error message makes sense.
 1.2 20-Dec-2016  maya branches: 1.2.2; 1.2.8;
use labs for absolute value of long
should fix arm build
 1.1 19-Dec-2016  maya add test for fesetround/fegetround that uses lrint (and tests it a bunch).
It doesn't fail on amd64.
 1.2.8.2 29-Aug-2017  martin Pull up the following, requested by he in ticket #217:

lib/libm/Makefile 1.197-1.201
tests/lib/libm/t_fe_round.c 1.7

Ensure nexttowardf() is included on all IEEE targets.
Add rintl() for aarch64 and mips, and nexttoward() for m68k.
Add a test which verifies that nextafter() and nexttoward() are
present in the implementation.
 1.2.8.1 29-Aug-2017  martin Pull up the following, requested by he in ticket #212:

lib/libm/Makefile 1.192-1.196
tests/lib/libm/t_fe_round.c 1.3-1.6

Ensure that nearbyint() is included in all targets except for vax,
and add a test case for nearbyint(), stubbed out for non-IEEE (vax).
 1.2.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.2.2.1 20-Dec-2016  pgoyette file t_fe_round.c was added on branch pgoyette-localcount on 2017-01-07 08:56:55 +0000
 1.20.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 14-May-2024  riastradh t_fpsetmask, t_fenv: Skip fp exception trap tests on RISC-V.

No architectural support for fp exception traps.

While here, make the macros behave a little better as C statements.
 1.17 12-May-2024  riastradh tests/lib/libm/t_fenv: Work around PR 58253.
 1.16 18-Mar-2024  martin The fetestexcept_trap test case only makes sense on FPUs that implement
exceptions.
 1.15 20-Feb-2024  riastradh fenv(3): Fix fetestexcept to avoid side effects on trap state.

PR port-amd64/57949
 1.14 19-Feb-2024  riastradh fenv(3): Add test for PR port-amd64/57949.
 1.13 06-Nov-2023  riastradh t_fenv: Factor checks out of switch in checkrounding.

No functional change intended, just tidies up a bit.

PR port-mips/57680

XXX pullup-10
 1.12 06-Nov-2023  riastradh t_fenv: Use volatile intermediate to force rounding to double.

See comment for details about why this is necessary.

Should fix these tests on i386 (and perhaps m68k too).

PR port-mips/57680

XXX pullup-10
 1.11 05-Nov-2023  riastradh t_fenv: Improve diagnostics when rounding mode tests fail.

Print the correct input, and print the rounding mode for clarity so
you don't have to cross-reference it by line number.

PR port-mips/57680

XXX pullup-10
 1.10 05-Nov-2023  riastradh t_fenv: Add #pragma STDC FENV_ACCESS ON and verify FLT_RADIX is 2.

Except gcc doesn't implement this pragma, so make it conditional.

And clang only supports it on some architectures, so just leave it
out for now with a comment about why.

PR port-mips/57680

XXX pullup-10
 1.9 05-Nov-2023  riastradh t_fenv: Verify rounding mode takes effect.

At least for addition operations, anyway.

Somewhat redundant with the test t_fe_round added by maya@ but this
gives two minimal pairs to easily diagnose exactly what the rounding
mode is when the wrong one was selected.

PR port-mips/57680

XXX pullup-10
 1.8 05-Nov-2023  riastradh t_fenv: Check FLT_ROUNDS whenever we touch the rounding mode.

PR port-mips/57680

XXX pullup-10
 1.7 05-Nov-2023  riastradh t_fenv: Print wrong values if tests fail.

XXX pullup-10
 1.6 25-Apr-2019  kamil branches: 1.6.2; 1.6.10;
Fix typo in 'exceptions'
 1.5 30-Jan-2019  martin Clean up terminology: modern arm CPUs do properly implement IEEE 754
floating point exceptions - but some (actually all currently know ones)
do not implement sending traps when these exceptions are raised.

Pointed out by Peter Maydell.
 1.4 23-Jan-2019  martin There are aarch64 Cortex cpus that do not trap on some floating point
exceptions - so apply the arm handling for aarch64 as well.
 1.3 22-Dec-2015  christos branches: 1.3.8; 1.3.14; 1.3.16;
put have fenv stuff elsewhere.
 1.2 29-Dec-2014  martin Skip rounding mode tests on ARM FPUs that do not allow configuration of them.
 1.1 21-Dec-2014  martin Add a test program for basic fenv.h rounding mode/exception mask testing.
 1.3.16.1 10-Jun-2019  christos Sync with HEAD
 1.3.14.1 26-Jan-2019  pgoyette Sync with HEAD
 1.3.8.1 23-Feb-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1937):

tests/lib/libm/t_fenv.c: revision 1.14
tests/lib/libm/t_fenv.c: revision 1.15
lib/libm/arch/x86_64/fenv.c: revision 1.11

fenv(3): Add test for PR port-amd64/57949.

fenv(3): Fix fetestexcept to avoid side effects on trap state.

PR port-amd64/57949
 1.6.10.2 03-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #816):

tests/lib/libm/t_fenv.c: revision 1.16

The fetestexcept_trap test case only makes sense on FPUs that implement
exceptions.
 1.6.10.1 23-Feb-2024  martin Pull up following revision(s) (requested by riastradh in ticket #603):

tests/lib/libm/t_fenv.c: revision 1.14
tests/lib/libm/t_fenv.c: revision 1.15
lib/libm/arch/x86_64/fenv.c: revision 1.11

fenv(3): Add test for PR port-amd64/57949.

fenv(3): Fix fetestexcept to avoid side effects on trap state.

PR port-amd64/57949
 1.6.2.1 23-Feb-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1801):

tests/lib/libm/t_fenv.c: revision 1.14
tests/lib/libm/t_fenv.c: revision 1.15
lib/libm/arch/x86_64/fenv.c: revision 1.11

fenv(3): Add test for PR port-amd64/57949.

fenv(3): Fix fetestexcept to avoid side effects on trap state.

PR port-amd64/57949
 1.9 12-Sep-2011  jruoho Merge 't_floor' to 't_ceil', and simplify.
 1.8 29-Aug-2011  jruoho Remove some cruft that is no longer needed.
 1.7 29-Aug-2011  jruoho Remove Xfails that are related to the infamous qemu/amd64 floating point
bugs. It appears to be quite difficult to identify the exact Qemu version
and setup. These do not fail on the TNF's qemu/amd64 setup, which can be
taken as a reference point for expected failures.
 1.6 07-Jul-2011  jruoho Improve the QEMU/amd64 detection.
 1.5 04-Jul-2011  mrg XXX: ugly hack to make these valid for vax fp.
XXX: could consolidate some of this into a common header, but i'll
leave that clean up for another time.
 1.4 25-Mar-2011  jruoho Do not skip the QEMU bugs but instead mark these as expected failures.
 1.3 25-Mar-2011  jruoho Bluntly skip the tests that fail under QEMU. XXX: system(3) is used for this?

wnCVS: ----------------------------------------------------------------------
 1.2 25-Mar-2011  jruoho Even these naive test cases caught one (QEMU?) bug; comment PR # 44767.
 1.1 24-Mar-2011  jruoho Add dummy test cases for ceil(3) and floor(3). It is expected that at least
one of these will fail on guest x86_64 NetBSD under Qemu. Thanks to pgoyette@
for checking the broken floor(16.999999...) = 17.
 1.4 25-Aug-2020  gson Only expect the fmod test case to fail when using qemu's TCG CPU emulation,
and not under hardware virtualization such as qemu -accel nvmm.
 1.3 03-Jan-2015  gson Mark the lib/libm/t_fmod test as an expected failure under QEMU,
with a reference to PR misc/44767.
 1.2 27-Feb-2014  joerg branches: 1.2.4; 1.2.6; 1.2.8;
Avoid promotion in subexpressions.
 1.1 12-Nov-2013  joerg Initial version of fmodl from FreeBSD.
Basic test case for the fmod family.
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 27-Feb-2014  tls file t_fmod.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.2.6.1 12-Jan-2015  snj Pull up following revision(s) (requested by gson in ticket #413):
tests/lib/libm/Makefile: revision 1.31
tests/lib/libm/t_fmod.c: revision 1.3
Mark the lib/libm/t_fmod test as an expected failure under QEMU,
with a reference to PR misc/44767.
 1.2.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.1 27-Feb-2014  yamt file t_fmod.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.9 07-Apr-2025  riastradh tests: Use `#if __*_HAS_DENORM__', not `#ifdef __*_HAS_DENORM__'.

The compiler defines this to zero on, e.g., VAX.

PR port-vax/59261: t_fpclassify tests are failing
 1.8 13-May-2024  rillig branches: 1.8.2;
tests/t_hypot: actually add nan test
 1.7 12-May-2024  riastradh t_hypot: Use an ld80 test case that actually fits in ld80.

Also add comments explaining how I generated these test cases.

(No autoconf back doors hidden in these magic numbers, I promise! No
pythagoreans were harmed in the production of these tests either.)
 1.6 11-May-2024  riastradh tests/lib/libm/t_hypot: Check inf/nan cases too.
 1.5 11-May-2024  riastradh hypotl(3): Fix includes and macros.

1. Need <math.h> for __HAVE_LONG_DOUBLE.
2. Need <machine/ieee.h> for struct ieee_ext_u &c.
3. EXT_FRACLBITS, not LDBL_MANL_SIZE.

PR lib/58245: hypotl is broken on ld128 ports
 1.4 11-May-2024  riastradh tests/lib/libm/t_hypot: More trivial tests.

Check both signs of zero.
 1.3 11-May-2024  riastradh tests/lib/libm/t_hypot: Expand substantially.

PR lib/58245: hypotl is broken on ld128 ports
 1.2 25-Jun-2020  jruoho Reference PRs consistently.
 1.1 24-Jan-2016  gson Add some tests of hypot() and hypotf()
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 14-May-2024  riastradh t_ilogb: Nix spurious line break in ATF_CHECK_MSG.
 1.10 09-May-2024  riastradh tests/lib/libm/t_ilogb: Expand and tidy.

1. Instead of calling out VAX by name, use #ifdef NAN and
isinf(INFINITY). (VAX defines INFINITY even though it's not an
infinity, not sure if there's a better compile-time test.)

2. Verify ilogbl works on long double on all architectures, not just
those with __HAVE_LONG_DOUBLE which means long double is _larger_
than double.
 1.9 14-Jun-2018  maya for consistency, print the statement that is true in the error case.
also add missing closing paren
 1.8 14-Jun-2018  maya Test for FE_INVALID in a way that works for powerpc too.

powerpc seems to return FE_INVALID | FE_VXSOFT rather than just FE_INVALID.
XXX need extra careful reading of standards
 1.7 13-Jan-2017  christos branches: 1.7.12;
PR/51837: Ngie Cooper: add limits.h for INT_MAX
 1.6 26-Aug-2016  christos branches: 1.6.2;
forgot to protect an ilogbl
 1.5 24-Aug-2016  christos fix test; clearing the exception does not return the old exception bitmask.
 1.4 24-Aug-2016  christos fix long double
 1.3 23-Aug-2016  christos portability fixes
 1.2 22-Aug-2016  maya Mistakes were made, compare correct values now.
 1.1 22-Aug-2016  maya add failing test for PR lib/51427
ilogb(INFINITY)=-INT_MAX, it should be INT_MAX

while here, test raised exceptions, other values.

XXX some platforms don't have exceptions
 1.6.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.6.2.2 14-Sep-2016  pgoyette Sync with HEAD
 1.6.2.1 26-Aug-2016  pgoyette file t_ilogb.c was added on branch pgoyette-localcount on 2016-09-14 03:04:19 +0000
 1.7.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.7 09-May-2024  riastradh tests/lib/libm/t_infinity: Remove broken long double conditional.

LDBL_MAX is always defined, so this branch is dead. (If LDBL_MAX is
not defined, that's a bug in the architecture's float.h, not a reason
to skip a test.)
 1.6 26-Sep-2012  jruoho Remove expected failures that no longer fail (probably due a Qemu update).
 1.5 08-Jul-2011  jruoho branches: 1.5.2; 1.5.8;
Remove the amd64-part from the Qemu checks. The following tests fail also on
i386/qemu: 'strtold_inf', 'strtold_nan', and 'infinity_long_double'. It seems
that more than anything else, these are dependent on the used Qemu version.
 1.4 07-Jul-2011  jruoho Improve the QEMU/amd64 detection.
 1.3 31-May-2011  alnsn Add <stdlib.h> for system(3).
 1.2 31-May-2011  jruoho Mark the following tests as expected failures on qemu/amd64: 'strtod_inf',
'strtod_round', and 'infinity_long_double'. None of these fail on any known
native host. Use the tracker PR misc/44767 as the reference point.
 1.1 11-Apr-2011  martin Try to generate infinite values in all available floating point formats
on the FPU and check isinf() and fpclassify() results. This is
different from the libc internal consistency checks testing PR
lib/33262.
 1.5.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.5.2.1 30-Oct-2012  yamt sync with head
 1.17 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.16 25-Aug-2016  maya branches: 1.16.12; 1.16.14;
Add a failing case for t_ldexp

ldexp(2.0, INT_MAX) should be HUGE_VAL, not 0
 1.15 25-Aug-2016  maya don't skip the entire test iteration if exp2=SKIP, only the second
application of the function

this doesn't introduce new failures on amd64
 1.14 04-Nov-2014  justin PR misc/49356 remove unnecessary references to atf-c/config.h

The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
 1.13 12-Mar-2014  martin Avoid double constants out of range
 1.12 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.11 09-Feb-2014  jmmv Use compiler builtins instead of atf_arch and atf_machine.

The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
 1.10 19-Sep-2011  jruoho branches: 1.10.2; 1.10.8;
Move duplicate ldexp(3) test out from the tests/libc.
 1.9 17-Sep-2011  jruoho Reduce the powers.
 1.8 16-Sep-2011  jruoho Adjust to see where this fails on i386/qemu.
 1.7 14-Sep-2011  jruoho Fix bug/oversight.
 1.6 14-Sep-2011  jruoho Use fabsf(3) when appropriate.
 1.5 13-Sep-2011  jruoho Test ldexp(x, n) == x * exp2(n) && ldexpf(x, n) == x * exp2f(n).
 1.4 12-Sep-2011  jruoho Improve the metadata descriptions.
 1.3 12-Sep-2011  jruoho Happiness of VAX implies ugliness of the code.
 1.2 12-Sep-2011  jruoho Add more assertions.
 1.1 12-Sep-2011  jruoho Start systematic testing of libm(3) by first evaluating the corner cases
(NaN, +0.0, -0.0, +Inf, -Inf) for the ldexp(3) and scalbn(3) families.
 1.10.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.14.1 10-Jun-2019  christos Sync with HEAD
 1.16.12.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.2 08-Apr-2011  jruoho Move the round(3) checks from 't_libm' to their own 't_round'
for consistency. Add -Wfloat-equal and fix comparisons.
 1.1 20-Dec-2010  pgoyette Move the only regress/lib/libm test to the new atf format
 1.7 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.6 25-Mar-2014  joerg branches: 1.6.4; 1.6.8; 1.6.28; 1.6.30;
Consistently use long double.
 1.5 16-Mar-2014  dsl Print the result as a 'long double' - on i386 a return value that
should be infinity might just be too large for 'double' and won't
get converted until it has to be saved to memory.
 1.4 16-Mar-2014  dsl Check that the result isn't equaly to the expected value before checking
the absolute size of the error term.
If the expected result is +/-infinity it should compare equal, but the
result of the subtract may not be zero.
Also print the result and error values in fp hex to make it easier to
see how may lsb bits are incorrect.
 1.3 07-Mar-2014  martin Vax does not do +/- INF.
 1.2 05-Mar-2014  dsl Fix some typos.
Make the infinity and nan constants 'double' not 'long double'.
 1.1 05-Mar-2014  dsl Move the #defines that simplified the test definitions and checks
into a separate header than can be used by the other libm tests.
Make the subtest index 'unsigned int' so that simple constants (eg 0)
print correctly.
 1.6.30.1 10-Jun-2019  christos Sync with HEAD
 1.6.28.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.6.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.8.1 25-Mar-2014  tls file t_libm.h was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.6.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.1 25-Mar-2014  yamt file t_libm.h was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.19 17-Jul-2024  riastradh tests/lib/libm/t_log.c: Record xfail for PR port-i386/58434.

PR port-i386/58434: single-float functions return surprisingly much
precision
 1.18 17-Jul-2024  riastradh libm: Fix order of significand words in EXTRACT_LDBL128_WORDS.

PR lib/58337
 1.17 16-Jul-2024  riastradh tests/lib/libm/t_log: Expand some more.

- Test nontrivial bit patterns for log, log2, log10, log1p.
- Print long double with %.34g, not %.17g.
- Sprinkle xfail for the ld128 code.

PR lib/58337: logl() crashes on arm64
 1.16 15-Jul-2024  riastradh tests/lib/libm/t_log.c: Expand to handle many more cases.

Also make this much more concise.

Prompted by PR lib/58337: logl() crashes on arm64
 1.15 09-Jun-2024  riastradh branches: 1.15.2;
tests/lib/libm: Fix various xfails related to PR lib/45362.

Writing

if (condition) {
atf_tc_expect_fail(...);
atf_tc_fail(...);
}

in order to paper over a bug in qemu renders the test nearly useless
because it will never actually fail in the event that something
unexpected is broken.

atf_tc_expect_fail only makes senes _before_ doing the test. If we
want to paper over a bug in qemu, we can do:

if (isQEMU)
atf_tc_expect_fail("qemu is broken, PR lib/...");
ATF_CHECK(condition);

That way, we are still doing the test in non-qemu circumstances, and
if the qemu bug is fixed the test will give the feedback of an
unexpected pass.

While here: Use `volatile double x = ...' as input so the compiler
doesn't optimize calls like sin(x) away at build-time, and print the
bad values with ATF_CHECK_MSG on failure in case anything goes wrong.
 1.14 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.13 09-Feb-2015  martin branches: 1.13.14; 1.13.16;
Remove expected failure and references to port-alpha/46301, now that
it is fixed.
 1.12 04-Nov-2014  justin PR misc/49356 remove unnecessary references to atf-c/config.h

The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
 1.11 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.10 27-Feb-2014  joerg Avoid promotion in subexpressions.
 1.9 09-Feb-2014  jmmv Use compiler builtins instead of atf_arch and atf_machine.

The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
 1.8 08-Apr-2012  jruoho branches: 1.8.2;
Remove one xfail that does not seem to fail (on alpha).
 1.7 06-Apr-2012  jruoho Point to PR port-alpha/46301 when failing on Alpha.
 1.6 05-Feb-2012  matt Change eps to fit within the VAX FP range.
 1.5 18-Sep-2011  jruoho branches: 1.5.2;
Add few basic checks.
 1.4 13-Sep-2011  jruoho When failing, point to the tracker PR lib/45362.
 1.3 12-Sep-2011  jruoho Expand the test file to contain 48 individual test cases.
 1.2 12-Apr-2011  jruoho PR lib/41931 should be fixed; remove expected failure.
 1.1 10-Apr-2011  jruoho Add a test case for PR lib/41931 reported by he@. It was verified that these
fail on NetBSD 5.99.48 amd64 but pass on amd64 Linux (glibc 2.7).
 1.5.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.2.1 17-Apr-2012  yamt sync with head
 1.8.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.13.16.1 10-Jun-2019  christos Sync with HEAD
 1.13.14.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.15.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 15-May-2024  riastradh modfl(3): Fix conversion from FreeBSD.

LDBL_MANL_SIZE is spelled EXT_FRACLBITS -- and not EXT_FRACHBITS.

PR lib/58237: modfl returns wrong answers on ld128 architectures
 1.5 08-May-2024  riastradh tests/lib/libm/t_modf: Mark modfl xfail on ld128.

PR lib/58237: modfl returns wrong answers on ld128 architectures
 1.4 06-May-2024  riastradh tests/lib/libm/t_modf: Use isinf(INFINITY) to detect inf support.

Apparently VAX defines the INFINITY macro even though it's not
actually an infinity and isinf returns zero for it.
 1.3 06-May-2024  riastradh tests/lib/libm/t_modf: Check sign of modf on infinities too.

Normally I don't like CHECK(A && B) and favour CHECK(A); CHECK(B)
instead, so you can see which one failed, but in this case the inputs
are displayed anyway so we don't lose anything unless the
floating-point printer is broken.
 1.2 06-May-2024  riastradh tests/lib/libm/t_modf.c: Expand modf/modff/modfl tests.

1. Exercise more edge cases around the largest exponent that can
represent non-integers.

2. - Verify modf can handle all cases modff can.
- Veriy modf can handle some cases modff can't.
- Verify modfl can handle all cases modf or modff can.
- If long double isn't just double, verify modfl can handle some
cases modf and modff can't.

3. Check infinities and NaN.

4. Verify oddness, i.e., modf(-x) = -modf(x).

5. Display more useful diagnostics in case any of this goes wrong.
 1.1 16-Jun-2014  joerg branches: 1.1.2; 1.1.6;
Add modfl(3). From FreeBSD.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 16-Jun-2014  tls file t_modf.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 16-Jun-2014  tls file t_modf.c was added on branch tls-earlyentropy on 2014-08-10 06:57:22 +0000
 1.8 07-Apr-2025  riastradh tests: Use `#if __*_HAS_DENORM__', not `#ifdef __*_HAS_DENORM__'.

The compiler defines this to zero on, e.g., VAX.

PR port-vax/59261: t_fpclassify tests are failing
 1.7 12-May-2024  riastradh branches: 1.7.2; 1.7.4; 1.7.6;
tests/lib/libm/t_next: Disable a test if long double is double.

This test, to verify nexttoward(x, x*(1 - LDBL_EPSILON/2)) moves in
the direction of x*(1 - LDBL_EPSILON/2), only makes sense if long
double has more precision than double -- the point of the exercise is
to verify that nexttoward moves even if the direction parameter can't
be rounded to double. But if long double is just double, this test
makes no sense.
 1.6 11-May-2024  riastradh nexttoward(3): Fix high-word test on small positive subnormals.

By this point in the logic, x can't be zero, so it's either positive
or negative.

The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.

hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.

PR lib/58236
 1.5 11-May-2024  riastradh tests/lib/libm/t_next: nexttoward works if it's just nextafter.

It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
 1.4 08-May-2024  riastradh tests/lib/libm/t_next: Expand substantially.

This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
 1.3 05-May-2024  riastradh tests/lib/libm/t_next: Fix stub on VAX.

Tested building the wrong tree, oops.
 1.2 05-May-2024  riastradh tests/lib/libm/t_next: Disable this test on VAX.

But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.
 1.1 05-May-2024  riastradh tests/lib/libm: Test nextafter/nexttoward and variants.

The tests are fairly trivial but should work without any conditionals
about floating-point formats.
 1.7.6.3 15-Oct-2024  martin Additionally pull up following revision(s) (requested by riastradh in ticket #1906):

tests/lib/libm/t_next.c: revision 1.7

tests/lib/libm/t_next: Disable a test if long double is double.

This test, to verify nexttoward(x, x*(1 - LDBL_EPSILON/2)) moves in
the direction of x*(1 - LDBL_EPSILON/2), only makes sense if long
double has more precision than double -- the point of the exercise is
to verify that nexttoward moves even if the direction parameter can't
be rounded to double. But if long double is just double, this test
makes no sense.
 1.7.6.2 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #963):

tests/lib/libm/Makefile: revision 1.49
distrib/sets/lists/tests/mi: revision 1.1315
tests/lib/libm/t_next.c: revision 1.1
tests/lib/libm/t_next.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.435
tests/lib/libm/t_next.c: revision 1.3
tests/lib/libm/t_next.c: revision 1.4
tests/lib/libm/t_next.c: revision 1.5
tests/lib/libm/t_next.c: revision 1.6
lib/libm/src/s_nexttoward.c: revision 1.3
(all via patch)

tests/lib/libm: Test nextafter/nexttoward and variants.

The tests are fairly trivial but should work without any conditionals
about floating-point formats.
tests/lib/libm/t_next: Disable this test on VAX.

But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.

tests/lib/libm/t_next: Fix stub on VAX.
Tested building the wrong tree, oops.

tests/lib/libm/t_next: Expand substantially.

This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
tests/lib/libm/t_next: nexttoward works if it's just nextafter.

It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
nexttoward(3): Fix high-word test on small positive subnormals.

By this point in the logic, x can't be zero, so it's either positive
or negative.

The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
 1.7.6.1 12-May-2024  martin file t_next.c was added on branch netbsd-9 on 2024-10-13 15:09:57 +0000
 1.7.4.3 15-Oct-2024  martin Additionally pull up following revision(s) (requested by riastradh in ticket #963):

tests/lib/libm/t_next.c: revision 1.7

tests/lib/libm/t_next: Disable a test if long double is double.

This test, to verify nexttoward(x, x*(1 - LDBL_EPSILON/2)) moves in
the direction of x*(1 - LDBL_EPSILON/2), only makes sense if long
double has more precision than double -- the point of the exercise is
to verify that nexttoward moves even if the direction parameter can't
be rounded to double. But if long double is just double, this test
makes no sense.
 1.7.4.2 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #963):

tests/lib/libm/Makefile: revision 1.49
distrib/sets/lists/tests/mi: revision 1.1315
tests/lib/libm/t_next.c: revision 1.1
tests/lib/libm/t_next.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.435
tests/lib/libm/t_next.c: revision 1.3
tests/lib/libm/t_next.c: revision 1.4
tests/lib/libm/t_next.c: revision 1.5
tests/lib/libm/t_next.c: revision 1.6
lib/libm/src/s_nexttoward.c: revision 1.3

tests/lib/libm: Test nextafter/nexttoward and variants.

The tests are fairly trivial but should work without any conditionals
about floating-point formats.
tests/lib/libm/t_next: Disable this test on VAX.

But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.

tests/lib/libm/t_next: Fix stub on VAX.
Tested building the wrong tree, oops.

tests/lib/libm/t_next: Expand substantially.

This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
tests/lib/libm/t_next: nexttoward works if it's just nextafter.

It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
nexttoward(3): Fix high-word test on small positive subnormals.

By this point in the logic, x can't be zero, so it's either positive
or negative.

The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
 1.7.4.1 12-May-2024  martin file t_next.c was added on branch netbsd-10 on 2024-10-13 15:05:17 +0000
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 09-Jun-2024  riastradh tests/lib/libm/t_pow: Revamp.

1. Avoid the broken idiom

if (condition) {
atf_tc_expect_fail(...);
atf_tc_fail(...);
}

2. Sprinkle volatile and ATF_CHECK_MSG.
 1.5 20-Jan-2017  maya use isinf instead of isinff. this doesn't introduce a functional change -
isinf works for float as well, and is more portable.

from Ngie Cooper in PR bin/51838
 1.4 08-Sep-2015  dholland branches: 1.4.2; 1.4.4;
Clear the XFAIL from PR 45391.
 1.3 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.2 23-Sep-2011  jruoho branches: 1.2.2; 1.2.8;
More bugs in pow(3); cases for PR port-amd64/45391.
 1.1 17-Sep-2011  jruoho IEEE corner case tests for the pow(3) family (incl. PR lib/45372).
 1.2.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.4.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 06-May-2024  riastradh tests/lib/libm/t_precision: Nix __HAVE_LONG_DOUBLE conditionals.

long double and LDBL_EPSILON work even on architectures where long
double is the same as double, i.e., where the confusingly named
__HAVE_LONG_DOUBLE is not defined.
 1.3 27-Aug-2016  christos do the long double tests if we have long double.
 1.2 04-Nov-2014  justin PR misc/49356 remove unnecessary references to atf-c/config.h

The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
 1.1 11-Nov-2013  joerg branches: 1.1.4; 1.1.8;
NetBSD 6.99.26: Switch i386 and amd64 to the x87 default control word
as initial value for new processes. This means that long double
computations get the expected 63bit mantissa. Binaries tagged as
compiled for 6.99.25 and older get the old value.

Add a simple test case to ensure that double and long double computation
are working correctly.
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 11-Nov-2013  tls file t_precision.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.1 11-Nov-2013  yamt file t_precision.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.2 20-Sep-2024  rin branches: 1.2.2; 1.2.6;
t_remquo: Work around missing remquo(3) for vax

Part of PR port-vax/57881
 1.1 19-Sep-2024  gdt tests: Add test for remquo

This test currently fails, because remquo has bugs. (A bugfix will be
committed soon.) Test vectors derived from results from code by
Charles Karney in GeodesicLib/proj, and manually inspected.
 1.2.6.2 02-Aug-2025  perseant Sync with HEAD
 1.2.6.1 20-Sep-2024  perseant file t_remquo.c was added on branch perseant-exfatfs on 2025-08-02 05:58:08 +0000
 1.2.2.2 02-Oct-2024  martin Pull up following revision(s) (requested by gdt in ticket #912):

distrib/sets/lists/debug/mi: revision 1.449
lib/libm/src/s_remquo.c: revision 1.3
lib/libm/src/s_remquo.c: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1339
tests/lib/libm/t_remquo.c: revision 1.1
tests/lib/libm/t_remquo.c: revision 1.2
tests/lib/libm/Makefile: revision 1.51

tests: Add test for remquo

This test currently fails, because remquo has bugs. (A bugfix will be
committed soon.) Test vectors derived from results from code by
Charles Karney in GeodesicLib/proj, and manually inspected.

t_remquo: Work around missing remquo(3) for vax
Part of PR port-vax/57881

libm/remquo: Fix bug where wrong quotient was returned

Fix taken from FreeBSD:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=166463
https://cgit.freebsd.org/src/commit/lib/msun/src/s_remquo.c?id=1cbd288942b08217e99bf889e0967895d53af00c

FreeBSD commit message:
Fix a bug in remquo{,f,l}, in which the quotient didn't always have the
correct sign when the remainder was 0.
Fix a separate bug in remquo alone, in which the remainder and
quotient were both off by a bit in certain cases involving subnormal
remainders.
The bugs affected all platforms except amd64 and i386, on which the
routines are implemented in assembly.

(On NetBSD, this bug manifests on amd64.)

libm/remquo: Fix bug where remquo returned wrong sign of quo
ISO C requires that quo be congruent to the quotient mod 2^k and have
a particular sign. The current code can return 0 when it should be
negative.
Because the code chooses k=31 (for the requirement of congruence
modulo 2^k), the only value available (in ILP32 or LP64) that is
negative and congruent to 0 is 0x80000000. In the specific case of
wanting "-0", return 0x80000000.
Resolves t_remquo test failure.
 1.2.2.1 20-Sep-2024  martin file t_remquo.c was added on branch netbsd-10 on 2024-10-02 12:46:13 +0000
 1.10 02-Feb-2024  andvar fix various typos in comments.
 1.9 03-Sep-2017  wiz Fix verb form.
 1.8 03-Sep-2017  maya Use a global double to stop GCC from optimizing the test away
Better diagnostic messages
More familiar test for 'even number'
 1.7 30-Aug-2017  maya Add a short case for the alpha test failure

Now I see it's down to the choice of -mfp-trap-mode (n works, su/sui/u don't)
 1.6 30-Aug-2017  maya use PRIu64 to print uint64_t, don't print sizeof

fixes build. sorry, built tested an older version for 32bit.
 1.5 30-Aug-2017  maya Add test case for alpha's MPFR config test failure
This assert fires with -mieee, but not without it.
 1.4 11-Nov-2013  joerg Add initial version of ceill, floorl and roundl from FreeBSD.
 1.3 13-Sep-2011  jruoho branches: 1.3.2; 1.3.8;
Assign missing copyright to TNF.

XXX: If these originated from you, please modify accordingly.
 1.2 04-Jul-2011  mrg XXX: ugly hack to make these valid for vax fp.
XXX: could consolidate some of this into a common header, but i'll
leave that clean up for another time.
 1.1 08-Apr-2011  jruoho Move the round(3) checks from 't_libm' to their own 't_round'
for consistency. Add -Wfloat-equal and fix comparisons.
 1.3.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18 09-Jun-2024  riastradh tests/lib/libm: Fix various xfails related to PR lib/45362.

Writing

if (condition) {
atf_tc_expect_fail(...);
atf_tc_fail(...);
}

in order to paper over a bug in qemu renders the test nearly useless
because it will never actually fail in the event that something
unexpected is broken.

atf_tc_expect_fail only makes senes _before_ doing the test. If we
want to paper over a bug in qemu, we can do:

if (isQEMU)
atf_tc_expect_fail("qemu is broken, PR lib/...");
ATF_CHECK(condition);

That way, we are still doing the test in non-qemu circumstances, and
if the qemu bug is fixed the test will give the feedback of an
unexpected pass.

While here: Use `volatile double x = ...' as input so the compiler
doesn't optimize calls like sin(x) away at build-time, and print the
bad values with ATF_CHECK_MSG on failure in case anything goes wrong.
 1.17 06-May-2024  riastradh tests/lib/libm/t_scalbn: Nix __HAVE_LONG_DOUBLE conditionals.

If long double is the same as double, i.e., __HAVE_LONG_DOUBLE is
undefined, these tests should still pass, since they don't rely on
extra precision beyond double.
 1.16 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.15 03-Jun-2018  maya branches: 1.15.2;
Test and clear exception around scalbn calls.
Second part of PR bin/51834.

ifdef out vax to avoid netbsd-specific macros.
 1.14 13-Jan-2017  agc branches: 1.14.12;
also terminate 2 other statements properly
 1.13 13-Jan-2017  agc terminate the statement properly
 1.12 13-Jan-2017  christos PR/51839: Ngie Cooper: reset errno to 0 before calling scalbn*
 1.11 03-Mar-2014  martin branches: 1.11.8;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.10 24-May-2013  martin Backout previous - real fix for vax libm upcoming.
 1.9 23-May-2013  christos vaxinate the new tests.
 1.8 20-May-2013  martin Add a few test cases to test "ordinary" values with the various scalbn
variants. While there, make some spuriously failing tests print out the
broken values on failure.
 1.7 13-Sep-2011  jruoho branches: 1.7.2; 1.7.8;
Improve metadata once again.
 1.6 13-Sep-2011  jruoho Test that scalbn(x) == ldexp(2) whenever FLT_RADIX == 2 (like it should be
on all systems except exotic relics such as IBM 360).
 1.5 13-Sep-2011  jruoho When failing, point to the tracker PR lib/45362.
 1.4 12-Sep-2011  jruoho Improve the metadata descriptions.
 1.3 12-Sep-2011  jruoho Happiness of VAX implies ugliness of the code.
 1.2 12-Sep-2011  jruoho Add more assertions.
 1.1 12-Sep-2011  jruoho Start systematic testing of libm(3) by first evaluating the corner cases
(NaN, +0.0, -0.0, +Inf, -Inf) for the ldexp(3) and scalbn(3) families.
 1.7.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.8.1 23-Jun-2013  tls resync from head
 1.7.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14.12.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.14.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.15.2.1 10-Jun-2019  christos Sync with HEAD
 1.8 09-Jun-2024  riastradh tests/lib/libm: Fix various xfails related to PR lib/45362.

Writing

if (condition) {
atf_tc_expect_fail(...);
atf_tc_fail(...);
}

in order to paper over a bug in qemu renders the test nearly useless
because it will never actually fail in the event that something
unexpected is broken.

atf_tc_expect_fail only makes senes _before_ doing the test. If we
want to paper over a bug in qemu, we can do:

if (isQEMU)
atf_tc_expect_fail("qemu is broken, PR lib/...");
ATF_CHECK(condition);

That way, we are still doing the test in non-qemu circumstances, and
if the qemu bug is fixed the test will give the feedback of an
unexpected pass.

While here: Use `volatile double x = ...' as input so the compiler
doesn't optimize calls like sin(x) away at build-time, and print the
bad values with ATF_CHECK_MSG on failure in case anything goes wrong.
 1.7 27-May-2019  maya Print result of function we tested (sinf),
not of function we didn't test (sin).

no need to print 17 digits for a float.

from Riastradh.
 1.6 07-Nov-2018  riastradh Disable x87 implementations of sin, cos, tan.

The x87 hardware uses a bad approximation to pi for argument
reduction, and consequently yields bad answers for inputs near pi or
pi/2.

Tweak one tanf test whose doubly rounded output is a little too far
from the correct answer on the doubly rounded input.
 1.5 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.4 03-Mar-2014  martin branches: 1.4.24; 1.4.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.3 14-Sep-2011  jruoho branches: 1.3.2; 1.3.8;
Additions to PR lib/45362: the float variants cosf(3), sinf(3), and tanf(3)
do not detect NaN for positive and negative infinity on i386 (qemu).
 1.2 14-Sep-2011  jruoho Use fabsf(3) when appropriate.
 1.1 14-Sep-2011  jruoho Some tests for sine, cosine, and tangent.
 1.3.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.26.1 10-Jun-2019  christos Sync with HEAD
 1.4.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.2 06-May-2024  riastradh tests/lib/libm/t_sincos: Nix __HAVE_LONG_DOUBLE conditionals.

sincosl is supposed to be there even if long double is double, as is
the case when __HAVE_LONG_DOUBLE is undefined.
 1.1 27-Aug-2022  christos Add sincos{,f,l} from FreeBSD
 1.7 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.6 03-Mar-2014  martin branches: 1.6.24; 1.6.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.5 09-Apr-2013  isaki Use a pre-calculated value as expected result, instead of
comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
 1.4 18-Oct-2011  jruoho branches: 1.4.2; 1.4.8;
Reduce tolerance even more.
 1.3 18-Oct-2011  jruoho Adjust and add some printfs.
 1.2 16-Oct-2011  jruoho As couple of checks fails on i386/qemu, reduce tolerance.
 1.1 16-Oct-2011  jruoho Basic IEEE tests for the hyperbolic sine and cosine.
 1.4.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 23-Jun-2013  tls resync from head
 1.4.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.26.1 10-Jun-2019  christos Sync with HEAD
 1.6.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.8 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.7 12-Mar-2014  martin branches: 1.7.24; 1.7.26;
Avoid double constants out of range
 1.6 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.5 22-Nov-2013  martin Adjust expected epsilon for sqrtl <-> powl comparisions for defects in
powl (which actually is pow for now)
 1.4 19-Nov-2013  joerg Add cbrtl(3) and sqrtl(3), from FreeBSD.
 1.3 13-Feb-2012  jruoho branches: 1.3.6;
Fix wrong error failure message.
 1.2 19-Nov-2011  mlelstv The compiler is allowed to use intermediate higher precision for float
arithmetic, which may cause differences smaller than float precision
but still much larger than eps = 1e-30.
Forcing intermediate results to volatile variables removes the excess
precision.
 1.1 16-Oct-2011  jruoho branches: 1.1.2;
Basic checks for the root functions.
 1.1.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.3.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.26.1 10-Jun-2019  christos Sync with HEAD
 1.7.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.8 09-Jun-2024  riastradh tests/lib/libm: Fix various xfails related to PR lib/45362.

Writing

if (condition) {
atf_tc_expect_fail(...);
atf_tc_fail(...);
}

in order to paper over a bug in qemu renders the test nearly useless
because it will never actually fail in the event that something
unexpected is broken.

atf_tc_expect_fail only makes senes _before_ doing the test. If we
want to paper over a bug in qemu, we can do:

if (isQEMU)
atf_tc_expect_fail("qemu is broken, PR lib/...");
ATF_CHECK(condition);

That way, we are still doing the test in non-qemu circumstances, and
if the qemu bug is fixed the test will give the feedback of an
unexpected pass.

While here: Use `volatile double x = ...' as input so the compiler
doesn't optimize calls like sin(x) away at build-time, and print the
bad values with ATF_CHECK_MSG on failure in case anything goes wrong.
 1.7 07-Nov-2018  riastradh Disable x87 implementations of sin, cos, tan.

The x87 hardware uses a bad approximation to pi for argument
reduction, and consequently yields bad answers for inputs near pi or
pi/2.

Tweak one tanf test whose doubly rounded output is a little too far
from the correct answer on the doubly rounded input.
 1.6 07-Nov-2018  riastradh Fix up libm tests.

- Fix up last few digits of a lot of known-answer tests.

Confirmed with GNU mpfr to 200 bits of precision and cross-checked
with whatever libm Ubuntu ships with.

- Test relative error, not absolute error.

- Set bounds in terms of *_EPSILON, not magic numbers.

*_EPSILON is twice the largest relative error of a correctly
rounded operation, and equal to the largest relative error of an
operation with up to 1ulp error.

Most of the operations we're testing are not correctly rounded, but
they ought to be no more than 1ulp away. For the few cases where
that's not a priori clear (like comparing cbrt and pow(x, 1/3)),
use twice *_EPSILON to allow some leeway.

- Write the success condition positively as error <= eps.

This comes out false if the result is a NaN, meaning failure. In
contrast, if we write error > eps for the _failure_ condition, then
if the result is a NaN, it will also come out false, but meaning
success, which is not what we want.

- Fix the trigonometric test cases near bad spots.

sin(pi - d) for nonzero d is not zero; it is d + O(d^3). pi is not
a floating-point number, so these results should be approximately
the nonzero error of our approximation to pi. Likewise with
cos(pi/2 - d) and tan(pi + d).

(Yes, I know the sin _function_ is ill-conditioned near pi so you
shouldn't pass approximate inputs near there, but that's separate
from whether a sin _implementation_ gives an answer that is wrong
by quintillions of ulps.)

Since on x86 (i386 and amd64 alike) we currently use x87 hardware
trigonometric instructions, which are bad, these are marked xfail
on x86 for now until we switch to software implementations (coming
soon to a repository near you).

- Use %.8g, %.17g, %.35g to print float, double, long double in failures.

This should be enough to identify the problematic outputs and/or
reproduce the computation, even if long double is binary128 with
115 bits of precision.

If there are any new libm test failures after this, tell me what
architecture you're on and send me the atf output and I'll try to
figure it out.
 1.5 03-Mar-2014  martin branches: 1.5.24; 1.5.26;
Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.4 15-Sep-2011  he branches: 1.4.2; 1.4.8;
#ifdef on __vax__ one more place, to avoid reference to tanf() for vax.
 1.3 14-Sep-2011  jruoho Additions to PR lib/45362: the float variants cosf(3), sinf(3), and tanf(3)
do not detect NaN for positive and negative infinity on i386 (qemu).
 1.2 14-Sep-2011  jruoho Use fabsf(3) when appropriate.
 1.1 14-Sep-2011  jruoho Some tests for sine, cosine, and tangent.
 1.4.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.26.1 10-Jun-2019  christos Sync with HEAD
 1.5.24.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.7 03-Mar-2014  martin Remove all cargo-cult #ifndef __vax__ from the tests, that just paper
over bugs in the vax libm.
 1.6 12-Sep-2011  jruoho branches: 1.6.2; 1.6.8;
Improve the metadata descriptions.
 1.5 12-Sep-2011  jruoho Happiness of VAX implies ugliness of the code.
 1.4 12-Sep-2011  jruoho Be more systematic and coarse-grained.
 1.3 26-Apr-2011  martin When failing, point to PR lib/44057 and the discussion therein about the
relevant compiler bug.
 1.2 08-Apr-2011  jruoho Fix build failure on VAX.
 1.1 06-Apr-2011  jruoho A test case for PR lib/44057.
 1.6.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")

RSS XML Feed