Skip to content
Commit 3a1d8e6f authored by Szabolcs Nagy's avatar Szabolcs Nagy
Browse files

Add simple ULP error check code

Check ULP error by random sampling and comparing against a higher
precision implmenetation.

This is similar to the randomized tests in the mathtest code, but it
runs on the target only and is much faster to allow exhaustive ULP
checks for single precision functions.  It also supports non-nearest
rounding modes.

The ULP error is reported in an unconventional way: instead of the
difference between the observed rounded result and accurate result, the
minimum error is reported that makes the accurate result round to the
observed result.  This is more useful for comparing errors across
different rounding modes.  In nearest-rounding mode usually 0.5 has to
be added to the reported error to get the conventional ULP error.

The code optionally depends on mpfr.  On targets where double has the
same format as long double, mpfr is required for testing double
precision functions.  By default there is no dependency on mpfr on the
target, to use mpfr add -DUSE_MPFR to the CFLAGS and -lmpfr to LDLIBS.

ucheck is a new make target for running ulp error checks.

Typical usage and output of the new ulp tool:

$ build/bin/ulp -e .001 exp 1.0 2.0 12345
exp(0x1.79ef3658a63c9p+0) got 0x1.181caa32757a7p+2 want 0x1.181caa32757a6p+2 +0.499708 ulp err 0.000291756
exp(0x1.9c8a65340f80cp+0) got 0x1.40a8032e5f576p+2 want 0x1.40a8032e5f575p+2 +0.498903 ulp err 0.00109668
FAIL exp in [0x1p+0;0x1p+1] round n errlim 0.001 maxerr 0.00109668 +0.5 cnt 12345 cnt1 6 0.0486027% cnt2 0 0% cntfail 1 0.00810045%

Floating-point exceptions are not guaranteed to be reported accurately
and can be turned off by -f.

The implementation is generic over the argument types which complicates
the code, but at least the difficult inner loop logic is not repeated
many times this way.

To add support for a new function foo, the fun array needs to be updated
with an entry for foo.  (This usually requires the functions foo, fool
and mpfr_foo to be defined.)
parent d1db92e0
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment