Skip to content

Commit

Permalink
Fix bug with negative exponents.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpitasky committed Aug 3, 2023
1 parent 26bc8c3 commit 5639227
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Float {
} else {
Flags::empty()
},
exponent: Self::EXPONENT_NORM + (exponent as u8),
exponent: (exponent as u8).wrapping_add(Self::EXPONENT_NORM),
mantissa: Mantissa::from(mantissa).unwrap(),
}
}
Expand Down Expand Up @@ -295,6 +295,14 @@ impl Div for Float {
mod tests {
use super::*;

#[test]
fn negative_exponents() {
assert_eq!(
tifloat!(0x10000000000000 * 10 ^ -2).exponent,
Float::EXPONENT_NORM - 2
);
}

#[test]
fn try_add_sub() {
let large = tifloat!(0x50000000000000 * 10 ^ 5);
Expand Down

0 comments on commit 5639227

Please sign in to comment.