Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
move ensure module and ArithmeticError to sp-arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Dec 20, 2022
1 parent 404cfdf commit 47df1eb
Show file tree
Hide file tree
Showing 4 changed files with 544 additions and 541 deletions.
28 changes: 28 additions & 0 deletions primitives/arithmetic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ pub use rational::{Rational128, RationalInfinite};
use sp_std::{cmp::Ordering, fmt::Debug, prelude::*};
use traits::{BaseArithmetic, One, SaturatedConversion, Unsigned, Zero};

use codec::{Decode, Encode};
use scale_info::TypeInfo;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

/// Arithmetic errors.
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum ArithmeticError {
/// Underflow.
Underflow,
/// Overflow.
Overflow,
/// Division by zero.
DivisionByZero,
}

impl From<ArithmeticError> for &'static str {
fn from(e: ArithmeticError) -> &'static str {
match e {
ArithmeticError::Underflow => "An underflow would occur",
ArithmeticError::Overflow => "An overflow would occur",
ArithmeticError::DivisionByZero => "Division by zero",
}
}
}

/// Trait for comparing two numbers with an threshold.
///
/// Returns:
Expand Down
Loading

0 comments on commit 47df1eb

Please sign in to comment.