@@ -15,6 +15,8 @@ const FD4 = FixedDecimal{Int, 4}
1515const WFD2 = FixedDecimal{Int128, 2 }
1616const WFD4 = FixedDecimal{Int128, 4 }
1717
18+ const CONTAINER_TYPES = [subtypes (Signed); subtypes (Unsigned)]
19+
1820# these arrays should be kept sorted manually
1921const keyvalues = Dict (
2022 FD2 => [typemin (FD2), # near minimum range
6870# ensure that the coefficient multiplied by the highest and lowest representable values of
6971# the container type do not result in overflow.
7072@testset " coefficient" begin
71- container_types = [Int8, Int16, Int32, Int64, Int128]
72- for (i, T) in enumerate (container_types)
73- for j in i: length (container_types)
74- f = FixedPointDecimals. max_exp10 (container_types[j])
73+ for (i, T) in enumerate (CONTAINER_TYPES)
74+ for j in i: length (CONTAINER_TYPES)
75+ f = FixedPointDecimals. max_exp10 (CONTAINER_TYPES[j])
7576 powt = FixedPointDecimals. coefficient (FD {T, f} (0 ))
7677 @test checked_mul (powt, typemax (T)) == powt * typemax (T)
7778 @test checked_mul (powt, typemin (T)) == powt * typemin (T)
@@ -441,10 +442,16 @@ end
441442 @test string (FixedDecimal {Int,0} (123.4 )) == " 123"
442443
443444 # Displaying a decimal could be incorrect when using a decimal place precision which is
444- # close to or at the limit the limit for our storage type. Int32 for example can only
445- # store up to 10 digits of precision.
446- @test string (reinterpret (FD{Int32,10 }, typemax (Int32))) == " 0.2147483647"
447- @test string (reinterpret (FD{Int32,10 }, typemin (Int32))) == " -0.2147483648"
445+ # close to or at the limit for our storage type.
446+ for T in CONTAINER_TYPES
447+ f = FixedPointDecimals. max_exp10 (T) + 1
448+ max_str = " 0." * rpad (typemax (T), f, ' 0' )
449+ min_str = (typemin (T) < 0 ? " -" : " " ) * " 0." * rpad (abs (widen (typemin (T))), f, ' 0' )
450+ @eval begin
451+ @test string (reinterpret (FD{$ T,$ f}, typemax ($ T))) == $ max_str
452+ @test string (reinterpret (FD{$ T,$ f}, typemin ($ T))) == $ min_str
453+ end
454+ end
448455end
449456
450457@testset " show" begin
0 commit comments