From 02aa0b08665c5d5ff34ec344c21ba17c0f8d6a07 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Sat, 26 Nov 2022 06:47:30 +0600 Subject: [PATCH] Fix overflow in pow5 (#47511) Fixup for #46764 --- base/ryu/utils.jl | 2 +- test/ryu.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/ryu/utils.jl b/base/ryu/utils.jl index e87d245aa4ee8..4fe0b7d397d07 100644 --- a/base/ryu/utils.jl +++ b/base/ryu/utils.jl @@ -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) diff --git a/test/ryu.jl b/test/ryu.jl index cf60e4867e236..0b10bd7e49ba5 100644 --- a/test/ryu.jl +++ b/test/ryu.jl @@ -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)