@@ -2071,6 +2071,7 @@ end
20712071Base.:+ (a:: Num , b:: Num ) = Num (a. x + b. x)
20722072Base.:- (a:: Num , b:: Num ) = Num (a. x - b. x)
20732073Base.:* (a:: Num , b:: Num ) = Num (a. x * b. x)
2074+ Base.:< (a:: Num , b:: Num ) = a. x < b. x
20742075Base. promote_rule (:: Type{Num} , :: Type{<:Real} ) = Num
20752076Base. ArithmeticStyle (:: Type{Num} ) = Base. ArithmeticRounds ()
20762077Base. OrderStyle (:: Type{Num} ) = Base. Unordered ()
@@ -2079,6 +2080,18 @@ Base.OrderStyle(::Type{Num}) = Base.Unordered()
20792080 # Test that @generated functions work with Quantities + custom types (#231)
20802081 @test uconvert (u " °C" , Num (373.15 )u " K" ) == Num (100 )u " °C"
20812082end
2083+ area_of_circle (radius:: similar_dims (u " m" )) = pi * radius^ 2
2084+ area_of_square (side:: similar_units (u " m" )) = side^ 2
2085+
2086+ @testset " Unitful interfaces" begin
2087+ @test area_of_circle (Num (1.0 )u " m" ) ≈ pi * m^ 2
2088+ @test area_of_circle (Num (1.0 )u " km" ) ≈ pi * km^ 2
2089+ @test_throws MethodError area_of_circle (Num (1.0 )u " s" )
2090+
2091+ @test area_of_square (Num (0.5 )u " m" ) ≈ 0.25 * m^ 2
2092+ @test_throws MethodError area_of_square (Num (0.5 )u " km" )
2093+ @test_throws MethodError area_of_square (Num (0.5 )u " s" )
2094+ end
20822095
20832096@testset " Traits" begin
20842097 @testset " > ArithmeticStyle" begin
0 commit comments