diff --git a/src/float/fast_float/ascii_number.cr b/src/float/fast_float/ascii_number.cr index a6bb00cdd91c..1c4b43ea4b7d 100644 --- a/src/float/fast_float/ascii_number.cr +++ b/src/float/fast_float/ascii_number.cr @@ -135,8 +135,8 @@ module Float::FastFloat p += 1 end end_of_integer_part = p - digit_count = (end_of_integer_part - start_digits).to_i64! - answer.integer = Slice.new(start_digits, digit_count.to_i32) + digit_count = (end_of_integer_part - start_digits).to_i32! + answer.integer = Slice.new(start_digits, digit_count) if fmt.json_fmt? # at least 1 digit in integer part, without leading zeros if digit_count == 0 @@ -162,7 +162,7 @@ module Float::FastFloat i = i &* 10 &+ digit # in rare cases, this will overflow, but that's ok end exponent = before - p - answer.fraction = Slice.new(before, (p - before).to_i32) + answer.fraction = Slice.new(before, (p - before).to_i32!) digit_count &-= exponent end if fmt.json_fmt? @@ -246,7 +246,7 @@ module Float::FastFloat int_end = p + answer.integer.size minimal_nineteen_digit_integer = 1000000000000000000_u64 while i < minimal_nineteen_digit_integer && p != int_end - i = i &* 10 &+ (p.value - '0'.ord).to_u64! + i = i &* 10 &+ (p.value &- '0'.ord).to_u64! p += 1 end if i >= minimal_nineteen_digit_integer # We have a big integers @@ -255,7 +255,7 @@ module Float::FastFloat p = answer.fraction.to_unsafe frac_end = p + answer.fraction.size while i < minimal_nineteen_digit_integer && p != frac_end - i = i &* 10 &+ (p.value - '0'.ord).to_u64! + i = i &* 10 &+ (p.value &- '0'.ord).to_u64! p += 1 end exponent = (answer.fraction.to_unsafe - p) &+ exp_number diff --git a/src/float/fast_float/bigint.cr b/src/float/fast_float/bigint.cr index 5783b3454b7f..14b0bb2d0549 100644 --- a/src/float/fast_float/bigint.cr +++ b/src/float/fast_float/bigint.cr @@ -250,9 +250,12 @@ module Float::FastFloat # multiply bigint by scalar value. def self.small_mul(vec : Stackvec(Size)*, y : Limb) : Bool forall Size carry = Limb.zero - vec.value.map_with_index! do |xi, i| + i = 0 + while i < vec.value.size + xi = vec.value.unsafe_fetch(i) z, carry = scalar_mul(xi, y, carry) - z + vec.value.unsafe_put(i, z) + i &+= 1 end if carry != 0 fastfloat_try vec.value.try_push(carry) @@ -270,8 +273,10 @@ module Float::FastFloat end carry = false - y.each_with_index do |yi, index| + index = 0 + while index < y.size xi = x.value.unsafe_fetch(index &+ start) + yi = y.unsafe_fetch(index) c2 = false xi, c1 = scalar_add(xi, yi) if carry @@ -279,6 +284,7 @@ module Float::FastFloat end x.value.unsafe_put(index &+ start, xi) carry = c1 || c2 + index &+= 1 end # handle overflow @@ -440,7 +446,8 @@ module Float::FastFloat elsif @vec.size < other.value.@vec.size -1 else - @vec.size.downto(1) do |index| + index = @vec.size + while index > 0 xi = @vec.unsafe_fetch(index &- 1) yi = other.value.@vec.unsafe_fetch(index &- 1) if xi > yi @@ -448,6 +455,7 @@ module Float::FastFloat elsif xi < yi return -1 end + index &-= 1 end 0 end @@ -464,10 +472,12 @@ module Float::FastFloat shl = n shr = LIMB_BITS &- n prev = Limb.zero - @vec.map_with_index! do |xi, index| - (xi.unsafe_shl(shl) | prev.unsafe_shr(shr)).tap do - prev = xi - end + index = 0 + while index < @vec.size + xi = @vec.unsafe_fetch(index) + @vec.unsafe_put(index, xi.unsafe_shl(shl) | prev.unsafe_shr(shr)) + prev = xi + index &+= 1 end carry = prev.unsafe_shr(shr)