Skip to content

Commit

Permalink
Add modf (#539)
Browse files Browse the repository at this point in the history
* Add `modf` for dimensionless quantities

* Add tests for `modf`

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
  • Loading branch information
rashidrafeek and sostock authored Jun 3, 2022
1 parent 960e09e commit 7f5bf1f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ end
Base.mod2pi(x::DimensionlessQuantity) = mod2pi(uconvert(NoUnits, x))
Base.mod2pi(x::AbstractQuantity{S, NoDims, <:Units{(Unitful.Unit{:Degree, NoDims}(0, 1//1),),
NoDims}}) where S = mod(x, 360°)
Base.modf(x::DimensionlessQuantity) = modf(uconvert(NoUnits, x))

# Addition / subtraction
for op in [:+, :-]
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ end
@test mod(1hr+3minute+5s, 24s) == 17s
@test mod2pi(360°) === 0° # 2pi is 360°
@test mod2pi(0.5pi*u"m/dm") pi # just testing the dimensionless fallback
@test modf(2.5rad) === (0.5, 2.0)
@test modf(-250cm/m) === (-1//2, -2//1)
@test_throws MethodError modf(1m)
@test @inferred(inv(s)) === s^-1
@test inv(ContextUnits(m,km)) === ContextUnits(m^-1,km^-1)
@test inv(FixedUnits(m)) === FixedUnits(m^-1)
Expand Down

0 comments on commit 7f5bf1f

Please sign in to comment.