Skip to content

Commit 26a1558

Browse files
authored
Test that upreferred also preserves float precision (#793)
1 parent f8a3e6b commit 26a1558

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

test/runtests.jl

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,19 @@ Base.:*(x::MyFloat64, y::Float64) = x.num * y
276276
@test uconvert(u"kOe^1000", 1u"kOe^1001 * Oe^-1") === 1000u"kOe^1000"
277277
# Issue 753:
278278
# preserve the floating point precision of quantities
279-
@test Unitful.numtype(uconvert(m, BigFloat(100)cm)) === BigFloat
280-
@test Unitful.numtype(uconvert(cm, (BigFloat(1+ im) * m)) === Complex{BigFloat}
281-
@test Unitful.numtype(uconvert(rad, BigFloat(360)°)) === BigFloat
282-
@test Unitful.numtype(uconvert(°, (BigFloat(2+ im) * rad)) === Complex{BigFloat}
283-
@test Unitful.numtype(uconvert(m, 100.0cm)) === Float64
284-
@test Unitful.numtype(uconvert(cm, (1.0π + im) * m)) === ComplexF64
285-
@test Unitful.numtype(uconvert(rad, 360.0°)) === Float64
286-
@test Unitful.numtype(uconvert(°, (2.0π + im) * rad)) === ComplexF64
287-
@test Unitful.numtype(uconvert(m, 100f0cm)) === Float32
288-
@test Unitful.numtype(uconvert(cm, (1f0π + im) * m)) === ComplexF32
289-
@test Unitful.numtype(uconvert(rad, 360f0°)) === Float32
290-
@test Unitful.numtype(uconvert(°, (2f0π + im) * rad)) === ComplexF32
291-
@test Unitful.numtype(uconvert(m, Float16(100)cm)) === Float16
292-
@test Unitful.numtype(uconvert(cm, (Float16(1+ im) * m)) === ComplexF16
293-
@test Unitful.numtype(uconvert(rad, Float16(360)°)) === Float16
294-
@test Unitful.numtype(uconvert(°, (Float16(2+ im) * rad)) === ComplexF16
279+
for T = [Float16, Float32, Float64, BigFloat]
280+
@test Unitful.numtype(uconvert(m, T(100)cm)) === T
281+
@test Unitful.numtype(uconvert(cm, (T(1+ im) * m)) === Complex{T}
282+
@test Unitful.numtype(uconvert(rad, T(360)°)) === T
283+
@test Unitful.numtype(uconvert(°, (T(2+ im) * rad)) === Complex{T}
284+
@test typeof(upreferred(T(360)°)) === T
285+
end
295286
@test uconvert(rad, NonReal(360)°) == uconvert(rad, 360°)
296287
@test uconvert(rad, ErrReal(360)°) == uconvert(rad, 360°)
297288
@test uconvert(rad, MyFloat64(360)°) == uconvert(rad, 360°)
289+
@test upreferred(NonReal(360)°) == upreferred(360°)
290+
@test upreferred(ErrReal(360)°) == upreferred(360°)
291+
@test upreferred(MyFloat64(360)°) == upreferred(360°)
298292
# Floating point overflow/underflow in uconvert can happen if the
299293
# conversion factor is large, because uconvert does not cancel
300294
# common basefactors (or just for really large exponents and/or

0 commit comments

Comments
 (0)