Expand description
§Anchor Safe Math
anchor_safe_math is a collection of helper numeric operation functions that removes the
verbosity of checking for overflow, underflow and division by zero errors.
§Examples
use solana_safe_math::{SafeMath};
use solana_program::{entrypoint::ProgramResult};
fn process_init_escrow(
accounts: &[AccountInfo],
amount: u64,
program_id: &Pubkey
) -> ProgramResult {
let val = 10_u64;
val.safe_add(amount)?;
val.safe_sub(amount)?;
val.safe_mul(amount)?;
val.safe_div(amount)?;
val.safe_pow(8_u32)?;
}Enums§
Traits§
- Safe
Math - Defines a set of safe math operations that return a
ProgramErrorwhich is expected in an anchor instruction execution.