Skip to content

Commit 00285d9

Browse files
committed
Fix bug in min_with_max_digits
1 parent f4e72b1 commit 00285d9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/util.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ end
9393
end
9494

9595
Base.@pure maxdigits(::Type{T}) where {T} = ndigits(typemax(T))
96-
Base.@pure min_with_max_digits(::Type{T}) where {T} = convert(T, 10^(ndigits(typemax(T))-1))
96+
Base.@pure min_with_max_digits(::Type{T}) where {T} = convert(T, T(10)^(maxdigits(T)-1))
9797

9898
@inline function tryparsenext_base10(T, str,i,len)
9999
i0 = i
@@ -108,7 +108,7 @@ Base.@pure min_with_max_digits(::Type{T}) where {T} = convert(T, 10^(ndigits(typ
108108
y2 === nothing && return R(convert(T, 0)), i
109109
r = y2[1]; i = y2[2]
110110
end
111-
111+
112112
digits = 1
113113
ten = T(10)
114114
while true

test/runtests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ end
111111
@test tryparsenext(fromtype(Int64), "9223372036854775807", 1, 19) |> unwrap == (9223372036854775807, 20)
112112
@test tryparsenext(fromtype(Int64), "9223372036854775808", 1, 19) |> failedat == 1
113113
@test tryparsenext(fromtype(Int64), "19223372036854775808", 1, 20) |> failedat == 1
114-
114+
@test tryparsenext(fromtype(UInt64), "18446744073709551615", 1, 20) |> unwrap == (0xffffffffffffffff, 21)
115+
@test tryparsenext(fromtype(UInt64), "18446744073709551616", 1, 20) |> failedat == 1
116+
@test tryparsenext(fromtype(Int128), "170141183460469231731687303715884105727", 1, 39) |> unwrap == (170141183460469231731687303715884105727, 40)
117+
@test tryparsenext(fromtype(Int128), "170141183460469231731687303715884105728", 1, 39) |> failedat == 1
118+
@test tryparsenext(fromtype(UInt128), "340282366920938463463374607431768211455", 1, 39) |> unwrap == (0xffffffffffffffffffffffffffffffff, 40)
119+
@test tryparsenext(fromtype(UInt128), "340282366920938463463374607431768211456", 1, 39) |> failedat == 1
115120
end
116121

117122
import TextParse: StringToken

0 commit comments

Comments
 (0)