Skip to content

Fix loading on Julia nightly after the trigonometry rewrite - #42

Closed
maleadt wants to merge 1 commit into
mainfrom
tb/nightly-deg2rad
Closed

maleadt wants to merge 1 commit into
mainfrom
tb/nightly-deg2rad

Conversation

@maleadt

@maleadt maleadt commented Nov 5, 2026

Copy link
Copy Markdown
Member

GPUToolbox no longer loads on Julia nightly (1.15.0-DEV.482 and later):

ERROR: LoadError: UndefVarError: `deg2rad_ext` not defined in `Base.Math`
in expression starting at src/overlays/float64.jl:96

The float64_overrides table keeps Float32 sind, cosd, sincosd and tand from using Float64, by overriding deg2rad_ext, sin_kernel and cos_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_deg16 exists, 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 and tan16 overrides then pick ±sin or ±cos of 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. tand is 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. sind and cosd are within 1 ulp, like Base's own results, and exact results (including the signs of zeros, and ±Inf for tand) match Base's. Inference with the override table shows no Float64 left in sind, cosd, sincosd or tand for Float32, while Base's methods without the table still contain Float64.

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.
@maleadt maleadt closed this Nov 5, 2026
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