mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
parent
ef5c4735fb
commit
c497641e63
3 changed files with 33 additions and 6 deletions
|
@ -298,12 +298,36 @@ impl RocDec {
|
|||
};
|
||||
|
||||
// Calculate the high digits - the ones before the decimal point.
|
||||
match before_point.parse::<i128>() {
|
||||
Ok(answer) => match answer.checked_mul(Self::ONE_POINT_ZERO) {
|
||||
Some(hi) => hi.checked_add(lo).map(|num| Self(num.to_ne_bytes())),
|
||||
None => None,
|
||||
},
|
||||
Err(_) => None,
|
||||
let (is_pos, digits) = match before_point.chars().next() {
|
||||
Some('+') => (true, &before_point[1..]),
|
||||
Some('-') => (false, &before_point[1..]),
|
||||
_ => (true, before_point),
|
||||
};
|
||||
|
||||
let mut hi: i128 = 0;
|
||||
macro_rules! adjust_hi {
|
||||
($op:ident) => {{
|
||||
for digit in digits.chars() {
|
||||
if digit == '_' {
|
||||
continue;
|
||||
}
|
||||
|
||||
let digit = digit.to_digit(10)?;
|
||||
hi = hi.checked_mul(10)?;
|
||||
hi = hi.$op(digit as _)?;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
if is_pos {
|
||||
adjust_hi!(checked_add);
|
||||
} else {
|
||||
adjust_hi!(checked_sub);
|
||||
}
|
||||
|
||||
match hi.checked_mul(Self::ONE_POINT_ZERO) {
|
||||
Some(hi) => hi.checked_add(lo).map(|num| Self(num.to_ne_bytes())),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue