Skip to content

Commit

Permalink
Refactor BigDecimal handling and fix to_big_decimal.
Browse files Browse the repository at this point in the history
Updated the `BigDecimal` type alias to `fastnum::D512` for consistency. Modified the `to_big_decimal` function to account for the sign of the input, ensuring proper construction of `BigDecimal` instances.
  • Loading branch information
shuhuiluo committed Jan 5, 2025
1 parent fd228d3 commit bba761d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub mod prelude {

pub type BigInt = fastnum::I512;
pub type BigUint = fastnum::U512;
pub type BigDecimal = fastnum::UD512;
pub type BigDecimal = fastnum::D512;
pub type RoundingMode = fastnum::decimal::RoundingMode;
}

Expand Down
7 changes: 5 additions & 2 deletions src/utils/types.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::prelude::{BigDecimal, BigInt, BigUint};
use alloy_primitives::U256;
use fastnum::decimal::Context;
use fastnum::decimal::{Context, Sign};

#[inline]
#[must_use]
pub const fn to_big_decimal(value: BigInt) -> BigDecimal {
BigDecimal::from_parts(value.to_bits(), 0, Context::default())
match value.is_negative() {
false => BigDecimal::from_parts(value.to_bits(), 0, Sign::Plus, Context::default()),
true => BigDecimal::from_parts(value.to_bits(), 0, Sign::Minus, Context::default()),
}
}

#[inline]
Expand Down

0 comments on commit bba761d

Please sign in to comment.