Skip to content

Commit b36f9f0

Browse files
Merge pull request #280 from ChrisRackauckas-Claude/add-floatmax-floatmin
Add floatmax and floatmin methods for TrackedReal
2 parents 7cc6588 + 7d268d1 commit b36f9f0

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ReverseDiff"
22
uuid = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
3-
version = "1.16.1"
3+
version = "1.16.2"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/tracked.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ 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(::Type{T}) where {T<:TrackedReal} = floatmax(valtype(T))
437+
Base.floatmin(::Type{T}) where {T<:TrackedReal} = floatmin(valtype(T))
438+
436439
Base.floor(t::TrackedReal) = floor(value(t))
437440
Base.floor(::Type{R}, t::TrackedReal) where {R<:Real} = floor(R, value(t))
438441

test/TrackedTests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ tp = InstructionTape()
733733
tr_int = TrackedReal(v_int, d, tp)
734734
tr_float = TrackedReal(v_float, d, tp)
735735
tr_float2 = TrackedReal(v_float2, d2, tp)
736+
tr_float32 = TrackedReal(Float32(v_float), Float32(d), tp)
736737

737738
@test hash(tr_float) === hash(v_float)
738739
@test hash(tr_float, hash(1)) === hash(v_float, hash(1))
@@ -756,6 +757,11 @@ tr_rand = rand(MersenneTwister(1), TrackedReal{Int,Float64,Nothing})
756757
@test eps(tr_float) === eps(v_float)
757758
@test eps(typeof(tr_float)) === eps(Float64)
758759

760+
@test floatmin(typeof(tr_float)) === floatmin(Float64)
761+
@test floatmin(typeof(tr_float32)) === floatmin(Float32)
762+
@test floatmax(typeof(tr_float)) === floatmax(Float64)
763+
@test floatmax(typeof(tr_float32)) === floatmax(Float32)
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)