Skip to content

Commit 2cf9c5c

Browse files
committed
Add comment in parse_float
1 parent ab7d959 commit 2cf9c5c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/compute.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ fn parse_float(bytes: &[u8]) -> i32 {
3434
let sgn = 1 - 2 * neg as i32;
3535
let res = bytes.iter().skip(neg).fold(0, |acc, &byte| {
3636
let is_digit = byte.is_ascii_digit() as i32;
37+
// one of the bytes is b'.' which would cause integer overflow
38+
// if b'0' is subracted from it, and `is_digit` is 0 in that
39+
// case.
3740
let digit = (byte as i32).wrapping_sub(b'0' as i32);
3841
acc * (10 * is_digit + (1 - is_digit)) + digit * is_digit
3942
});

0 commit comments

Comments
 (0)