Skip to content

Commit 1043a59

Browse files
authored
Merge branch 'master' into dw/diffrules_complex
2 parents f111216 + e11936c commit 1043a59

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/dual.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ Base.copy(d::Dual) = d
294294
Base.eps(d::Dual) = eps(value(d))
295295
Base.eps(::Type{D}) where {D<:Dual} = eps(valtype(D))
296296

297+
# The `base` keyword was added in Julia 1.8:
298+
# https://github.com/JuliaLang/julia/pull/42428
299+
if VERSION < v"1.8.0-DEV.725"
300+
Base.precision(d::Dual) = precision(value(d))
301+
Base.precision(::Type{D}) where {D<:Dual} = precision(valtype(D))
302+
else
303+
Base.precision(d::Dual; base::Integer=2) = precision(value(d); base=base)
304+
function Base.precision(::Type{D}; base::Integer=2) where {D<:Dual}
305+
precision(valtype(D); base=base)
306+
end
307+
end
308+
297309
function Base.nextfloat(d::ForwardDiff.Dual{T,V,N}) where {T,V,N}
298310
ForwardDiff.Dual{T}(nextfloat(d.value), d.partials)
299311
end
@@ -316,6 +328,10 @@ Base.trunc(d::Dual) = trunc(value(d))
316328
Base.round(::Type{R}, d::Dual) where {R<:Real} = round(R, value(d))
317329
Base.round(d::Dual) = round(value(d))
318330

331+
Base.fld(x::Dual, y::Dual) = fld(value(x), value(y))
332+
333+
Base.cld(x::Dual, y::Dual) = cld(value(x), value(y))
334+
319335
if VERSION v"1.4"
320336
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
321337
else

test/DualTest.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
105105
@test eps(NESTED_FDNUM) === eps(PRIMAL)
106106
@test eps(typeof(NESTED_FDNUM)) === eps(V)
107107

108+
@test precision(FDNUM) === precision(PRIMAL)
109+
@test precision(typeof(FDNUM)) === precision(V)
110+
@test precision(NESTED_FDNUM) === precision(PRIMAL)
111+
@test precision(typeof(NESTED_FDNUM)) === precision(V)
112+
if VERSION >= v"1.8.0-DEV.725" # https://github.com/JuliaLang/julia/pull/42428
113+
@test precision(FDNUM; base=10) === precision(PRIMAL; base=10)
114+
@test precision(typeof(FDNUM); base=10) === precision(V; base=10)
115+
@test precision(NESTED_FDNUM; base=10) === precision(PRIMAL; base=10)
116+
@test precision(typeof(NESTED_FDNUM); base=10) === precision(V; base=10)
117+
end
118+
108119
@test floor(Int, FDNUM) === floor(Int, PRIMAL)
109120
@test floor(Int, FDNUM2) === floor(Int, PRIMAL2)
110121
@test floor(Int, NESTED_FDNUM) === floor(Int, PRIMAL)
@@ -137,6 +148,14 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
137148
@test round(FDNUM2) === round(PRIMAL2)
138149
@test round(NESTED_FDNUM) === round(PRIMAL)
139150

151+
@test fld(FDNUM, FDNUM2) === fld(PRIMAL, PRIMAL2)
152+
@test fld(FDNUM, PRIMAL2) === fld(PRIMAL, PRIMAL2)
153+
@test fld(PRIMAL, FDNUM2) === fld(PRIMAL, PRIMAL2)
154+
155+
@test cld(FDNUM, FDNUM2) === cld(PRIMAL, PRIMAL2)
156+
@test cld(FDNUM, PRIMAL2) === cld(PRIMAL, PRIMAL2)
157+
@test cld(PRIMAL, FDNUM2) === cld(PRIMAL, PRIMAL2)
158+
140159
@test div(FDNUM, FDNUM2) === div(PRIMAL, PRIMAL2)
141160
@test div(FDNUM, PRIMAL2) === div(PRIMAL, PRIMAL2)
142161
@test div(PRIMAL, FDNUM2) === div(PRIMAL, PRIMAL2)

0 commit comments

Comments
 (0)