Crates.io | safe_math |
lib.rs | safe_math |
version | 1.1.1 |
source | src |
created_at | 2023-05-25 19:13:58.257773 |
updated_at | 2024-10-08 12:42:11.948127 |
description | Math without overflow, creates an enum and a macro to help mitigate any overflow while multiplying and adding |
homepage | |
repository | https://github.com/XDDudeGuy/safe_math |
max_upload_size | |
id | 874551 |
size | 1,279,341 |
Adds a macro and an enum safe_math!()
and Operation
pub enum Operation {
...
}
Has two variants Add and Multiply with no fields, used in the safe_math!() macro to determine whether you are adding or multiplying the inputted numbers
#[macro_export]
macro_rules! safe_math {
($in_x:expr, $in_y:expr, $operation:expr)
}
This takes three expression arguments, the first two being the numbers you wish to use and the third being the operation you wish to apply to the numbers whether that be addition or multiplication. The first two expressions should be below the unsigned 64 bit integer limit and the third should be a variant of the Operation enum. Most errors will just return the larger of the two number input variables in the Err() variant of the Result enum