Skip to content

Define floatmin, floatmax, maxintfloat and issubnormal for Dual instances - #855

Merged
devmotion merged 3 commits into
masterfrom
dw/dual-float-constants
Nov 16, 2026
Merged

devmotion merged 3 commits into
masterfrom
dw/dual-float-constants

Conversation

@devmotion

Copy link
Copy Markdown
Member

Fixes #852.

Following JuliaLang/julia#63451, typemin, typemax, floatmin, floatmax and maxintfloat accept instances as well as types. Base only forwards instances of AbstractFloat to the type methods, so floatmin(::Dual), floatmax(::Dual) and maxintfloat(::Dual) threw a MethodError. So did maxintfloat(::Type{<:Dual}) and issubnormal(::Dual).

These functions now return the primal, which is what eps already did, and they're defined together with eps in one loop. Before, typemin/typemax/floatmin/floatmax returned a Dual with zero partials, which only added overhead and could produce NaNs.

🤖 Generated with Claude Code

@devmotion devmotion linked an issue Sep 30, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.05%. Comparing base (94425f7) to head (5024386).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #855      +/-   ##
==========================================
- Coverage   91.06%   91.05%   -0.02%     
==========================================
  Files          11       11              
  Lines        1086     1084       -2     
==========================================
- Hits          989      987       -2     
  Misses         97       97              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

devmotion and others added 2 commits November 3, 2026 22:43
…ual` instances (#852)

`typemin`, `typemax`, `floatmin`, `floatmax` and `maxintfloat` now return
the primal for both `Dual` instances and types instead of a `Dual` with
zero partials, which only added overhead and could produce NaNs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devmotion
devmotion force-pushed the dw/dual-float-constants branch from b0d87da to 8c66edc Compare November 3, 2026 21:45
devmotion added a commit that referenced this pull request Nov 3, 2026
- Drop the redundant `<:Real` bounds and share the constant-`a` check
- Bump version to 1.5.1 (on top of #855)
- Test the gradient of `DiffResults.hessian!`, which uses nested duals
- Test the derivative at `x = 0` for `a = 1` (from #862)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@StackEnjoyer

Copy link
Copy Markdown

Thanks for this PR. It would fix a downstream break for us, and I'd like to ask whether it could be merged and released before Julia 1.14 is final.

On Julia 1.14.0-alpha1, LinearAlgebra.normalize calls issubnormal, which has no method for Dual yet (#852). Code that normalizes a vector inside ForwardDiff.gradient therefore errors. For us that is BeamletOptics.jl, where surface normals come from the gradient of a signed distance function (StackEnjoyer/BeamletOptics.jl#173). Julia 1.12 is not affected.

v1.4.8 came out without this change, so our pre CI job is still red. Once 1.14 is released, the 1 job will be too. A 1.5.0 release with #855 before then would avoid that, and we are happy to test a branch or release candidate against our suite.

@devmotion
devmotion merged commit 730e156 into master Nov 16, 2026
21 of 22 checks passed
@devmotion
devmotion deleted the dw/dual-float-constants branch November 16, 2026 14:16
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.

missing floatmin, floatmax, and issubnormal for Dual

3 participants