Skip to content

Improve accuracy testing method#4

Open
jouae wants to merge 2 commits intoMax042004:mainfrom
jouae:benchtest
Open

Improve accuracy testing method#4
jouae wants to merge 2 commits intoMax042004:mainfrom
jouae:benchtest

Conversation

@jouae
Copy link
Copy Markdown
Contributor

@jouae jouae commented Nov 22, 2025

Improve testing method, including

  1. Fix the typo.
  2. Use GNU MPFR (GNU Multiple Precision Floating-Point Reliable)[1] to avoid relying on any particular standard library.
  3. Add output data in log (input x, referenced value, value of bf16_sin).

For example, range1.log

// absolute_error, input_bits (hex), ref_bits(MPFR), approx_bits(bf16_sin)
0.000000, 0x3e10, 0x3e10, 0x3e10

The difference of output is as following:

Test range [0.140625, pi/2]:
Max difference = 0.00390625, Total 56 numbers difference.

Test range [pi/2, +largest]:
- Max difference = 0.007812, Total 4623 numbers difference
+ Max difference = 0.0078125, Total 4567 numbers difference.

Test range [-smallest, -largest]:
- Max difference = 0.007812,Total 9270 numbers difference
+ Max difference = 0.0078125, Total 4647 numbers difference.

Close issue #3

Reference:
[1] https://www.mpfr.org/

The range1 should be [0.140625,pi/2], which is from 0x3E10 (0.140625)
to 0x3FC9 (1.5703125, rounded pi/2) and the representable number is
441 not 450.

Since the inf and -inf in BF16 are 0x7F80 and 0xFF80, the test range2
should be fixed as [pi/2,+largest], where +largest is the largest
positive normal BF16, that is +largest=0x7F7F.

Similarly, range3 should fixed as [-smallest, -largest], where -largest
is the largest negative normal BF16, that is +largest=0xFF7F.
The current accuracy testing method is based on the sinf implementation
in glibc. This implementation, introduced by Wilco Dijkstra in
release 2.29 [1], reports:

    Worst-case ULP is 0.5607, maximum relative error is 0.5303 * 2^-23

Use GNU MPFR (GNU Multiple Precision Floating-Point Reliable) [3], a
verified high-precision floating-point library, as the comparison
baseline—similar to the approach used in glibc benchtests.
This avoids relying on any particular standard library.

Reference:
[1] glibc - release 2.29 - s_sinf.c
[2] Gladman, B., Innocente, V., Mather, J., & Zimmermann, P. (2025).
    Accuracy of mathematical functions in single, double, double
    extended, and quadruple precision.
[3] https://www.mpfr.org/

Signed-off-by: jouae <oipc9801@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant