Skip to content

Commit 2403c89

Browse files
committed
Add floatmax and floatmin methods for TrackedReal
These methods delegate to the underlying value type, following the same pattern as eps. This fixes errors when code calls floatmax or floatmin on TrackedReal types during autodiff. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7cc6588 commit 2403c89

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/tracked.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ Base.rand(rng::Random.AbstractRNG, ::Type{TrackedReal{V,D,O}}) where {V,D,O} = T
433433
Base.eps(t::TrackedReal) = eps(value(t))
434434
Base.eps(::Type{T}) where {T<:TrackedReal} = eps(valtype(T))
435435

436+
Base.floatmax(t::TrackedReal) = floatmax(value(t))
437+
Base.floatmax(::Type{T}) where {T<:TrackedReal} = floatmax(valtype(T))
438+
439+
Base.floatmin(t::TrackedReal) = floatmin(value(t))
440+
Base.floatmin(::Type{T}) where {T<:TrackedReal} = floatmin(valtype(T))
441+
436442
Base.floor(t::TrackedReal) = floor(value(t))
437443
Base.floor(::Type{R}, t::TrackedReal) where {R<:Real} = floor(R, value(t))
438444

test/TrackedTests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ tr_rand = rand(MersenneTwister(1), TrackedReal{Int,Float64,Nothing})
756756
@test eps(tr_float) === eps(v_float)
757757
@test eps(typeof(tr_float)) === eps(Float64)
758758

759+
@test floatmax(tr_float) === floatmax(v_float)
760+
@test floatmax(typeof(tr_float)) === floatmax(Float64)
761+
762+
@test floatmin(tr_float) === floatmin(v_float)
763+
@test floatmin(typeof(tr_float)) === floatmin(Float64)
764+
759765
@test floor(tr_float) === floor(v_float)
760766
@test floor(Int, tr_float) === floor(Int, v_float)
761767

0 commit comments

Comments
 (0)