847847 out = x ^ (1 + 2im )
848848 @test typeof (out) == with_type_parameters (promote_quantity_on_value (Q, ComplexF64), Complex{Float64}, DEFAULT_DIM_TYPE)
849849 @test ustrip (out) ≈ 0.5 ^ (1 + 2im )
850+
851+ for CT in (Complex, Complex{Float32})
852+ x = Q (1.0 )
853+ @test CT (x) == CT (1.0 )
854+ @test typeof (CT (x)) <: CT
855+ x = Q (1.0 , length= 1 )
856+ @test_throws AssertionError CT (x)
857+ end
858+ end
859+ end
860+
861+ @testset " Bool" begin
862+ for Q in (RealQuantity, Quantity, GenericQuantity)
863+ x = Q (1.0 u " 1" )
864+ @test Bool (x) == true
865+ @test Bool (ustrip (x)) == true
866+ @test Bool (Q (0.0 u " m" )) == false
867+ @test Bool (ustrip (Q (0.0 u " m" ))) == false
868+ x = Q (1.0 u " m" )
869+ @test_throws AssertionError Bool (x)
850870 end
851871 end
852872end
@@ -1266,7 +1286,7 @@ end
12661286 :nextfloat , :prevfloat , :identity , :transpose ,
12671287 :copysign , :flipsign , :modf ,
12681288 :floor , :trunc , :ceil , :significand ,
1269- :ldexp , :round , # :mod
1289+ :ldexp , :round , :mod , :rem
12701290 )
12711291 for Q in (RealQuantity, Quantity, GenericQuantity), D in (Dimensions, SymbolicDimensions), f in functions
12721292 T = f in (:abs , :real , :imag , :conj ) ? ComplexF64 : Float64
@@ -1280,17 +1300,31 @@ end
12801300 @eval @test $ f ($ qx_dimensions)[$ i] == $ Q ($ f ($ x)[$ i], $ dim)
12811301 end
12821302 end
1283- elseif f in (:copysign , :flipsign , :rem ) # Functions that need multiple inputs
1303+ elseif f in (:copysign , :flipsign , :rem , :mod ) # Functions that need multiple inputs
12841304 for x in 5 rand (T, 3 ) .- 2.5
12851305 for y in 5 rand (T, 3 ) .- 2.5
12861306 dim = convert (D, dimension (u " m/s" ))
12871307 qx_dimensions = Q (x, dim)
12881308 qy_dimensions = Q (y, dim)
12891309 @eval @test $ f ($ qx_dimensions, $ qy_dimensions) == $ Q ($ f ($ x, $ y), $ dim)
1290- if f in (:copysign , :flipsign , :mod )
1310+ if f in (:copysign , :flipsign )
12911311 # Also do test without dimensions
12921312 @eval @test $ f ($ x, $ qy_dimensions) == $ f ($ x, $ y)
12931313 @eval @test $ f ($ qx_dimensions, $ y) == $ Q ($ f ($ x, $ y), $ dim)
1314+ elseif f in (:rem , :mod )
1315+ # Also do test without dimensions (need dimensionless)
1316+ qx_dimensionless = Q (x, D)
1317+ qy_dimensionless = Q (y, D)
1318+ @eval @test $ f ($ x, $ qy_dimensionless) == $ Q ($ f ($ x, $ y), $ D)
1319+ @eval @test $ f ($ qx_dimensionless, $ y) == $ Q ($ f ($ x, $ y), $ D)
1320+ @eval @test_throws DimensionError $ f ($ qx_dimensions, $ y)
1321+ @eval @test_throws DimensionError $ f ($ x, $ qy_dimensions)
1322+ if f == :rem
1323+ # Can also do other rounding modes
1324+ for r in (:RoundFromZero , :RoundNearest , :RoundUp , :RoundDown )
1325+ @eval @test $ f ($ qx_dimensions, $ qy_dimensions, $ r) == $ Q ($ f ($ x, $ y, $ r), $ dim)
1326+ end
1327+ end
12941328 end
12951329 end
12961330 end
0 commit comments