Repository navigation
Conversation
Ports Go's math.Atan and math.Atan2 (which are based on Cephes atan.c) to DSLX as fp_atan_32 and fp_atan2_32, alongside the existing fp_sincos_32 port. Like the other xls_go_math functions, subnormal inputs and outputs are flushed to zero and a canonical NaN is returned. Differences from the Go implementation: - Coefficients and constants are rounded to single precision; division uses fpdiv_2x32. - fp_atan_32 selects the reduced argument (x, -1/x or (x-1)/(x+1)) before evaluating xatan, so the three range-reduction cases share one divider and one xatan evaluation (two fpdiv_2x32 in total, counting the one in xatan's rational approximation). - The low-order bits of pi/2 and pi/4 (Morebits) are added to xatan's result before the high part, so they are not rounded away in single precision. - fp_atan2_32 picks the x < 0 quadrant correction from the sign of y rather than the sign of atan(y/x), so the result has the right sign when y/x underflows to zero, and adds pi as PI_LO + PI. Accuracy: on 10M random inputs per function (half uniform bit patterns, half uniform in [-4, 4]), every result is within 1 ulp of libm's double-precision result rounded to float. This can be reproduced by running the testbenches with --max_ulp_error=1 --num_samples=10000000. Testing: - DSLX unit tests for all special cases listed in Go's documentation, range-reduction boundaries, all quadrants, and y/x underflow/overflow. - fp_atan_32_test and fp_atan2_32_test: random-sampling JIT testbenches comparing against std::atan/std::atan2 with a 2 ulp tolerance.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports Go's math.Atan and math.Atan2 (which are based on Cephes atan.c) to DSLX as fp_atan_32 and fp_atan2_32, alongside the existing fp_sincos_32 port. Like the other xls_go_math functions, subnormal inputs and outputs are flushed to zero and a canonical NaN is returned.
Differences from the Go implementation:
Accuracy: on 10M random inputs per function (half uniform bit patterns, half uniform in [-4, 4]), every result is within 1 ulp of libm's double-precision result rounded to float. This can be reproduced by running the testbenches with --max_ulp_error=1 --num_samples=10000000.
Testing:
Fixes #5448.