@@ -15,6 +15,8 @@ const FD4 = FixedDecimal{Int, 4}
15
15
const WFD2 = FixedDecimal{Int128, 2 }
16
16
const WFD4 = FixedDecimal{Int128, 4 }
17
17
18
+ const CONTAINER_TYPES = [subtypes (Signed); subtypes (Unsigned)]
19
+
18
20
# these arrays should be kept sorted manually
19
21
const keyvalues = Dict (
20
22
FD2 => [typemin (FD2), # near minimum range
68
70
# ensure that the coefficient multiplied by the highest and lowest representable values of
69
71
# the container type do not result in overflow.
70
72
@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])
75
76
powt = FixedPointDecimals. coefficient (FD {T, f} (0 ))
76
77
@test checked_mul (powt, typemax (T)) == powt * typemax (T)
77
78
@test checked_mul (powt, typemin (T)) == powt * typemin (T)
@@ -441,10 +442,16 @@ end
441
442
@test string (FixedDecimal {Int,0} (123.4 )) == " 123"
442
443
443
444
# 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
448
455
end
449
456
450
457
@testset " show" begin
0 commit comments