Skip to content

Commit

Permalink
Fix overflow in pow5 (#47511)
Browse files Browse the repository at this point in the history
Fixup for #46764
  • Loading branch information
LilithHafner authored Nov 26, 2022
1 parent 04214ec commit 02aa0b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/ryu/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ lengthforindex(idx) = div(((Int64(16 * idx) * 1292913986) >> 32) + 1 + 16 + 8, 9
Return `true` if `5^p` is a divisor of `x`.
"""
pow5(x, p) = x % (5^p) == 0
pow5(x, p) = x % (UInt64(5)^p) == 0

"""
Ryu.pow2(x, p)
Expand Down
5 changes: 5 additions & 0 deletions test/ryu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ end
@test "2.305843009213694e40" == Ryu.writeshortest(Core.bitcast(Float64, 0x4850F0CF064DD592))
end

@testset "pow5 overflow (#47464)" begin
@test "4.6458339e+63" == Ryu.writeexp(4.645833859177319e63, 7)
@test "4.190673780e+40" == Ryu.writeexp(4.190673779576499e40, 9)
end

@testset "OutputLength" begin
@test "1.0" == Ryu.writeshortest(1.0) # already tested in Basic
@test "1.2" == Ryu.writeshortest(1.2)
Expand Down

0 comments on commit 02aa0b0

Please sign in to comment.