Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[extensions]
ConstructionBaseUnitfulExt = "ConstructionBase"
ForwardDiffExt = "ForwardDiff"
InverseFunctionsUnitfulExt = "InverseFunctions"
LatexifyExt = ["Latexify", "LaTeXStrings"]
NaNMathExt = "NaNMath"
PrintfExt = "Printf"

[compat]
Expand All @@ -33,6 +35,7 @@ InverseFunctions = "0.1"
LaTeXStrings = "1.2.0"
Latexify = "0.16.8"
LinearAlgebra = "<0.0.1, 1"
NaNMath = "1"
Printf = "<0.0.1, 1"
REPL = "<0.0.1, 1"
Random = "<0.0.1, 1"
Expand All @@ -47,10 +50,11 @@ InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "ConstructionBase", "ForwardDiff", "InverseFunctions", "Latexify", "LaTeXStrings", "LinearAlgebra", "Test", "Random", "REPL", "Printf"]
test = ["Aqua", "ConstructionBase", "ForwardDiff", "InverseFunctions", "Latexify", "LaTeXStrings", "LinearAlgebra", "NaNMath", "Test", "Random", "REPL", "Printf"]
7 changes: 7 additions & 0 deletions ext/NaNMathExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module NaNMathExt
using Unitful
import NaNMath

NaNMath.sqrt(q::Unitful.AbstractQuantity) = NaNMath.sqrt(ustrip(q))*sqrt(unit(q))
NaNMath.pow(q::Unitful.AbstractQuantity, r) = NaNMath.pow(ustrip(q), r)*unit(q)^r
end
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Unitful: DimensionError, AffineError
import Unitful: LogScaled, LogInfo, Level, Gain, MixedUnits, Decibel
import Unitful: FreeUnits, ContextUnits, FixedUnits, AffineUnits, AffineQuantity
import ForwardDiff
import NaNMath
import Latexify: Latexify, latexify, @latexify, FancyNumberFormatter, SiunitxNumberFormatter
import LaTeXStrings: LaTeXString, @L_str

Expand Down Expand Up @@ -2377,6 +2378,15 @@ if isdefined(Base, :get_extension)
@test ForwardDiff.Dual(1.0)*u"cm/m" + ForwardDiff.Dual(1.0) == 1.01
@test ForwardDiff.Dual(1.0)*u"cm/m" == ForwardDiff.Dual(0.01)
end

@testset "NaNMath extension" begin
@test isnan(NaNMath.sqrt(-1m))
@test unit(NaNMath.sqrt(-1m)) == m^(1//2)
@test isnan(NaNMath.pow(-1m, 0.5))
@test unit(NaNMath.pow(-1m, 0.5)) == m^(1//2)
@test NaNMath.sqrt(m) === Base.sqrt(m)
@test NaNMath.pow(m, 2) === m^2
end
end

struct Num <: Real
Expand Down
Loading