Repository navigation
Conversation
JuliaLang/julia#63544 rewrote the trigonometric functions around a table kernel and removed `deg2rad_ext`, `sin_kernel` and `cos_kernel`, so the overrides of those failed to load on nightly. `sind`, `cosd`, `sincosd` and `tand` for Float32 now reduce their argument in Float64 (`rem_deg16`) and evaluate a Float64 kernel. Where `rem_deg16` exists, override it to reduce exactly in Float32 to a multiple of 90 degrees plus an angle in [-45, 45] degrees, as Base used to, and override the kernels for that reduced angle so that they call `sin` and `cos`. Older versions keep the existing overrides.
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.
GPUToolbox no longer loads on Julia nightly (1.15.0-DEV.482 and later):
The
float64_overridestable keeps Float32sind,cosd,sincosdandtandfrom using Float64, by overridingdeg2rad_ext,sin_kernelandcos_kernel. JuliaLang/julia#63544 replaced Base's trigonometric kernels with a table-based one and removed all three. On nightly, these functions reduce a Float32 argument to n*11.25° + z in Float64 (rem_deg16) and evaluate a Float64 kernel on the result.Where
rem_deg16exists, this overrides it to do what Base did before: reduce the argument exactly in Float32 to a multiple of 90° plus an angle in [-45°, 45°], and convert that angle to radians with the existing split π/180 constant. The kernel andtan16overrides then pick ±sinor ±cosof the angle by quadrant, so back-ends supply the math as before. A multiple of 90° only needs the table entries 0 and ±1, so nothing is lost by not using the table. Older Julia versions keep the existing overrides. The gate checks for the binding instead of a version, because the change landed in the middle of the 1.15 development cycle and the overrides depend on these internals rather than on a release.I didn't use Base's Float32 kernel, because its polynomial is fitted for Float16 results and is only accurate to about 2^-23.
tandis still the quotient of the Float32 sine and cosine, as it was before (3 ulps worst case in my sampling).Tested with
Pkg.test()on Julia 1.10, 1.12, 1.13, 1.14.0-alpha2 and nightly. On nightly, I composed the overrides the way Base calls them and compared against BigFloat on about 240k inputs.sindandcosdare within 1 ulp, like Base's own results, and exact results (including the signs of zeros, and ±Inf fortand) match Base's. Inference with the override table shows no Float64 left insind,cosd,sincosdortandfor Float32, while Base's methods without the table still contain Float64.