oxedyne/fe2o3/fe2o3_num/src/macros.rs
1.6 KiB, 13 runs
created by r1870400018:637, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | #[macro_export] |
| 2 | /// Create an integer of arbitrary size using primitive integers. Can return an error. |
| 3 | /// |
| 4 | /// ``` |
| 5 | /// use oxedyne_fe2o3_core::prelude::*; // To handle the possible error. |
| 6 | /// use oxedyne_fe2o3_num::prelude::*; |
| 7 | /// |
| 8 | /// fn main() -> Outcome<()> { |
| 9 | /// let n = res!(aint!(fmt!("{}0", u128::MAX))); |
| 10 | /// Ok(()) |
| 11 | /// } |
| 12 | /// ``` |
| 13 | macro_rules! aint { |
| 14 | ( $v:expr ) => { |
| 15 | num_bigint::BigInt::from_str(&($v.to_string())) |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | //#[macro_export] |
| 20 | ///// Create an integer of arbitrary size from a str. |
| 21 | ///// |
| 22 | ///// ``` |
| 23 | ///// use oxedyne_fe2o3_core::prelude::*; |
| 24 | ///// use oxedyne_fe2o3_num::aintstr; |
| 25 | ///// use std::str::FromStr; |
| 26 | ///// use num_bigint::BigInt; |
| 27 | ///// |
| 28 | ///// fn main() -> Outcome<()> { |
| 29 | ///// let n = res!(aintstr!("-42")); |
| 30 | ///// Ok(()) |
| 31 | ///// } |
| 32 | ///// ``` |
| 33 | //macro_rules! aintstr { |
| 34 | // ( $v:expr ) => { |
| 35 | // { |
| 36 | // use std::str::FromStr; |
| 37 | // match num_bigint::BigInt::from_str($v) { |
| 38 | // Err(e) => Err(err!(e, errmsg!( |
| 39 | // "While interpreting '{}' as a BigInt", $v, |
| 40 | // ), ErrTag::String, ErrTag::Input, ErrTag::Decode, ErrTag::Numeric)), |
| 41 | // Ok(v) => Ok(v), |
| 42 | // } |
| 43 | // } |
| 44 | // }; |
| 45 | //} |
| 46 | |
| 47 | #[macro_export] |
| 48 | /// Create an arbitrary decimal via string conversion. Can return an error. |
| 49 | /// |
| 50 | /// ``` |
| 51 | /// use oxedyne_fe2o3_core::prelude::*; // To handle the possible error. |
| 52 | /// use oxedyne_fe2o3_num::prelude::*; |
| 53 | /// |
| 54 | /// fn main() -> Outcome<()> { |
| 55 | /// let n = res!(adec!(fmt!("{}0", f64::MAX))); |
| 56 | /// Ok(()) |
| 57 | /// } |
| 58 | /// ``` |
| 59 | macro_rules! adec { |
| 60 | ( $v:expr ) => { |
| 61 | bigdecimal::BigDecimal::from_str(&($v.to_string())) |
| 62 | }; |
| 63 | } |