Skip to content

Commit

Permalink
Add overloads for fld and cld (#581)
Browse files Browse the repository at this point in the history
* Add fld and cld

* Add new tests

* Increment patch number

* Match method defined in base

* Revert "Match method defined in base"

This reverts commit d676c2c.
  • Loading branch information
sethaxen authored Apr 24, 2022
1 parent eed0ff3 commit c85db12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ForwardDiff"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.25"
version = "0.10.26"

[deps]
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
Expand Down
4 changes: 4 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ Base.trunc(d::Dual) = trunc(value(d))
Base.round(::Type{R}, d::Dual) where {R<:Real} = round(R, value(d))
Base.round(d::Dual) = round(value(d))

Base.fld(x::Dual, y::Dual) = fld(value(x), value(y))

Base.cld(x::Dual, y::Dual) = cld(value(x), value(y))

if VERSION v"1.4"
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
else
Expand Down
8 changes: 8 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
@test round(FDNUM2) === round(PRIMAL2)
@test round(NESTED_FDNUM) === round(PRIMAL)

@test fld(FDNUM, FDNUM2) === fld(PRIMAL, PRIMAL2)
@test fld(FDNUM, PRIMAL2) === fld(PRIMAL, PRIMAL2)
@test fld(PRIMAL, FDNUM2) === fld(PRIMAL, PRIMAL2)

@test cld(FDNUM, FDNUM2) === cld(PRIMAL, PRIMAL2)
@test cld(FDNUM, PRIMAL2) === cld(PRIMAL, PRIMAL2)
@test cld(PRIMAL, FDNUM2) === cld(PRIMAL, PRIMAL2)

@test div(FDNUM, FDNUM2) === div(PRIMAL, PRIMAL2)
@test div(FDNUM, PRIMAL2) === div(PRIMAL, PRIMAL2)
@test div(PRIMAL, FDNUM2) === div(PRIMAL, PRIMAL2)
Expand Down

0 comments on commit c85db12

Please sign in to comment.