Skip to content

Commit 24505fc

Browse files
LilithHafnerKristofferC
authored andcommitted
Fix overflow in pow5 (#47511)
Fixup for #46764 (cherry picked from commit 02aa0b0)
1 parent aba112c commit 24505fc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

base/ryu/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ lengthforindex(idx) = div(((Int64(16 * idx) * 1292913986) >> 32) + 1 + 16 + 8, 9
6464
6565
Return `true` if `5^p` is a divisor of `x`.
6666
"""
67-
pow5(x, p) = x % (5^p) == 0
67+
pow5(x, p) = x % (UInt64(5)^p) == 0
6868

6969
"""
7070
Ryu.pow2(x, p)

test/ryu.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ end
5252
@test "2.305843009213694e40" == Ryu.writeshortest(Core.bitcast(Float64, 0x4850F0CF064DD592))
5353
end
5454

55+
@testset "pow5 overflow (#47464)" begin
56+
@test "4.6458339e+63" == Ryu.writeexp(4.645833859177319e63, 7)
57+
@test "4.190673780e+40" == Ryu.writeexp(4.190673779576499e40, 9)
58+
end
59+
5560
@testset "OutputLength" begin
5661
@test "1.0" == Ryu.writeshortest(1.0) # already tested in Basic
5762
@test "1.2" == Ryu.writeshortest(1.2)

0 commit comments

Comments
 (0)