Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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::Quantity) = NaNMath.sqrt(ustrip(q))*sqrt(unit(q))
NaNMath.pow(q::Quantity, r) = NaNMath.pow(ustrip(q), r)*unit(q)^r
Comment thread
Ickaser marked this conversation as resolved.
Outdated
end
6 changes: 6 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,11 @@ 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(-1u"m"))
@test isnan(NaNMath.pow(-1u"m", 0.5))
end
end

struct Num <: Real
Expand Down
Loading