Skip to content

Commit

Permalink
chore: add debug_assert to new decimal128
Browse files Browse the repository at this point in the history
  • Loading branch information
QuenKar committed Nov 16, 2023
1 parent 44a6591 commit a8f01cf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/common/decimal/src/decimal128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ pub struct Decimal128 {
impl Decimal128 {
/// Create a new Decimal128 from i128, precision and scale without any validation.
pub fn new(value: i128, precision: u8, scale: i8) -> Self {
// debug assert precision and scale is valid
debug_assert!(
precision > 0 && precision <= DECIMAL128_MAX_PRECISION,
"precision should be in [1, {}]",
DECIMAL128_MAX_PRECISION
);
debug_assert!(
scale >= 0 && scale <= precision as i8,
"scale should be in [0, precision]"
);
Self {
value,
precision,
Expand Down

0 comments on commit a8f01cf

Please sign in to comment.