Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Nov 15, 2024
1 parent 77a4987 commit 189e9e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/float/fast_float/ascii_number.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 18 additions & 8 deletions src/float/fast_float/bigint.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -270,15 +273,18 @@ 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
xi, c2 = scalar_add(xi, 1)
end
x.value.unsafe_put(index &+ start, xi)
carry = c1 || c2
index &+= 1
end

# handle overflow
Expand Down Expand Up @@ -440,14 +446,16 @@ 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
return 1
elsif xi < yi
return -1
end
index &-= 1
end
0
end
Expand All @@ -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)
Expand Down

0 comments on commit 189e9e0

Please sign in to comment.