diff --git a/Project.toml b/Project.toml index a08b93b9..2f877280 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Unitful" uuid = "1986cc42-f94f-5a68-af5c-568840ba703d" -version = "1.13.1" +version = "1.14.0" [deps] ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" @@ -13,11 +13,18 @@ Aqua = "0.6" ConstructionBase = "1" julia = "1" +[extensions] +InverseFunctionsUnitfulExt = "InverseFunctions" + [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "LinearAlgebra", "Test", "Random"] +test = ["Aqua", "InverseFunctions", "LinearAlgebra", "Test", "Random"] + +[weakdeps] +InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" diff --git a/ext/InverseFunctionsUnitfulExt.jl b/ext/InverseFunctionsUnitfulExt.jl new file mode 100644 index 00000000..1d73e922 --- /dev/null +++ b/ext/InverseFunctionsUnitfulExt.jl @@ -0,0 +1,8 @@ +module InverseFunctionsUnitfulExt +using Unitful +import InverseFunctions: inverse + +# `true` plays the role of 1, but doesn't promote unnecessary +inverse(f::Base.Fix1{typeof(ustrip), <:Unitful.Units}) = Base.Fix1(*, true*f.x) + +end diff --git a/test/runtests.jl b/test/runtests.jl index 00eec576..05eeb0af 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Unitful -using Test, LinearAlgebra, Random, ConstructionBase +using Test, LinearAlgebra, Random, ConstructionBase, InverseFunctions import Unitful: DimensionError, AffineError import Unitful: LogScaled, LogInfo, Level, Gain, MixedUnits, Decibel import Unitful: FreeUnits, ContextUnits, FixedUnits, AffineUnits, AffineQuantity @@ -85,6 +85,11 @@ const colon = Base.:(:) @test ConstructionBase.constructorof(typeof(1.0m))(2) === 2m end +VERSION >= v"1.9-" && @testset "inverse" begin + InverseFunctions.test_inverse(Base.Fix1(ustrip, m), 2m) + InverseFunctions.test_inverse(Base.Fix1(ustrip, m), 2mm) +end + @testset "Types" begin @test Base.complex(Quantity{Float64,NoDims,NoUnits}) == Quantity{Complex{Float64},NoDims,NoUnits}