Skip to content

Commit

Permalink
Add comment in parse_float
Browse files Browse the repository at this point in the history
  • Loading branch information
hesampakdaman committed May 22, 2024
1 parent ab7d959 commit 2cf9c5c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ fn parse_float(bytes: &[u8]) -> i32 {
let sgn = 1 - 2 * neg as i32;
let res = bytes.iter().skip(neg).fold(0, |acc, &byte| {
let is_digit = byte.is_ascii_digit() as i32;
// one of the bytes is b'.' which would cause integer overflow
// if b'0' is subracted from it, and `is_digit` is 0 in that
// case.
let digit = (byte as i32).wrapping_sub(b'0' as i32);
acc * (10 * is_digit + (1 - is_digit)) + digit * is_digit
});
Expand Down

0 comments on commit 2cf9c5c

Please sign in to comment.