[−][src]Struct no_proto::pointer::dec::NP_Dec
Holds fixed decimal data.
Check out documentation here.
Fields
num: i64
The number being stored, does not include decimal point data
exp: u8
The exponent of this number
Implementations
impl NP_Dec
[src]
pub fn to_float(&self) -> f64
[src]
Convert an NP_Dec into a native floating point value.
DO NOT use this to perform calculations, only to export/display the value.
use no_proto::pointer::dec::NP_Dec; let my_num = NP_Dec::new(2203, 3); // value is 2.203 assert_eq!(my_num.to_float(), 2.203f64);
pub fn shift_exp(&mut self, new_exp: u8) -> NP_Dec
[src]
Shift the exponent of this NP_Dec to a new value.
If the new exp
value is higher than the old exp
value, there may be an overflow of the i64 value.
If the new exp
value is lower than the old one, information will likely be lost as decimal precision is being removed from the number.
use no_proto::pointer::dec::NP_Dec; let mut my_num = NP_Dec::new(2203, 3); // value is 2.203 my_num.shift_exp(1); // set `exp` to 1 instead of 3. This will force our value to 2.2 assert_eq!(my_num.to_float(), 2.2_f64); // notice we've lost the "03" at the end because of reducing the `exp` value.
pub fn new(num: i64, exp: u8) -> Self
[src]
Generate a new NP_Dec value
First argument is the num
value, second is the exp
or exponent.
use no_proto::pointer::dec::NP_Dec; let x = NP_Dec::new(2, 0); // stores "2.00" assert_eq!(x.to_float(), 2f64); let x = NP_Dec::new(2, 1); // stores "0.20" assert_eq!(x.to_float(), 0.2f64); let x = NP_Dec::new(2, 2); // stores "0.02" assert_eq!(x.to_float(), 0.02f64); let x = NP_Dec::new(5928, 1); // stores "592.8" assert_eq!(x.to_float(), 592.8f64); let x = NP_Dec::new(59280, 2); // also stores "592.8" assert_eq!(x.to_float(), 592.8f64); let x = NP_Dec::new(592800, 3); // also stores "592.8" assert_eq!(x.to_float(), 592.8f64);
pub fn match_exp(&self, other: &NP_Dec) -> NP_Dec
[src]
Given another NP_Dec value, match the exp
value of this NP_Dec to the other one. Returns a copy of the other NP_Dec.
This creates a copy of the other NP_Dec then shifts it's exp
value to whatever self is, then returns that copy.
use no_proto::pointer::dec::NP_Dec; let mut my_num = NP_Dec::new(2203, 3); // value is 2.203 let other_num = NP_Dec::new(50, 1); // value is 5.0 let matched_dec = my_num.match_exp(&other_num); // `exp` values match now! They're both 3. assert_eq!(matched_dec.exp, my_num.exp);
pub fn export(&self) -> (i64, u8)
[src]
Export NP_Dec to it's component parts.
use no_proto::pointer::dec::NP_Dec; let my_num = NP_Dec::new(2203, 3); // value is 2.203 assert_eq!(my_num.export(), (2203i64, 3u8));
Trait Implementations
impl Add<NP_Dec> for NP_Dec
[src]
type Output = NP_Dec
The resulting type after applying the +
operator.
pub fn add(self, other: NP_Dec) -> Self::Output
[src]
impl AddAssign<NP_Dec> for NP_Dec
[src]
pub fn add_assign(&mut self, other: NP_Dec)
[src]
impl Clone for NP_Dec
[src]
pub fn clone(&self) -> NP_Dec
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for NP_Dec
[src]
impl Debug for NP_Dec
[src]
impl Default for NP_Dec
[src]
impl Div<NP_Dec> for NP_Dec
[src]
type Output = NP_Dec
The resulting type after applying the /
operator.
pub fn div(self, other: NP_Dec) -> Self::Output
[src]
impl DivAssign<NP_Dec> for NP_Dec
[src]
pub fn div_assign(&mut self, other: NP_Dec)
[src]
impl Into<NP_Dec> for i32
[src]
Converts an Int32 into a NP_Dec
use no_proto::pointer::dec::NP_Dec; let x = 101i32; let y: NP_Dec = x.into(); assert_eq!(y.num as i32, x);
impl Into<NP_Dec> for i64
[src]
Converts an Int64 into a NP_Dec
use no_proto::pointer::dec::NP_Dec; let x = 101i64; let y: NP_Dec = x.into(); assert_eq!(y.num, x);
impl Into<NP_Dec> for f64
[src]
Converts a Float64 into a NP_Dec
use no_proto::pointer::dec::NP_Dec; let x = 100.238f64; let y: NP_Dec = x.into(); assert_eq!(y.to_float(), x);
impl Into<NP_Dec> for f32
[src]
Converts a Float32 into a NP_Dec
use no_proto::pointer::dec::NP_Dec; let x = 100.238f32; let y: NP_Dec = x.into(); assert_eq!(y.to_float() as f32, x);
impl Into<f32> for NP_Dec
[src]
Converts a NP_Dec into a Float32
use no_proto::pointer::dec::NP_Dec; let x = NP_Dec::new(10023, 2); let y: f32 = x.into(); assert_eq!(y, x.to_float() as f32);
impl Into<f64> for NP_Dec
[src]
Converts a NP_Dec into a Float64
use no_proto::pointer::dec::NP_Dec; let x = NP_Dec::new(10023, 2); let y: f64 = x.into(); assert_eq!(y, x.to_float());
impl Into<i32> for NP_Dec
[src]
Converts an NP_Dec into an Int32, rounds to nearest whole number
use no_proto::pointer::dec::NP_Dec; let x = NP_Dec::new(10123, 2); let y: i32 = x.into(); assert_eq!(y, 101i32);
impl Into<i64> for NP_Dec
[src]
Converts an NP_Dec into an Int64, rounds to nearest whole number
use no_proto::pointer::dec::NP_Dec; let x = NP_Dec::new(10123, 2); let y: i64 = x.into(); assert_eq!(y, 101i64);
impl Mul<NP_Dec> for NP_Dec
[src]
type Output = NP_Dec
The resulting type after applying the *
operator.
pub fn mul(self, other: NP_Dec) -> Self::Output
[src]
impl MulAssign<NP_Dec> for NP_Dec
[src]
pub fn mul_assign(&mut self, other: NP_Dec)
[src]
impl NP_Scalar for NP_Dec
[src]
impl PartialEq<NP_Dec> for NP_Dec
[src]
Check if two NP_Dec are equal or not equal
If the two exp
values are not identical, unexpected results may occur due to rounding.
use no_proto::pointer::dec::NP_Dec; let result = NP_Dec::new(202, 1) == NP_Dec::new(202, 1); assert_eq!(result, true); let result = NP_Dec::new(202, 1) != NP_Dec::new(200, 1); assert_eq!(result, true); let result = NP_Dec::new(202, 1) == NP_Dec::new(2020, 2); assert_eq!(result, true); let result = NP_Dec::new(203, 1) != NP_Dec::new(2020, 2); assert_eq!(result, true);
impl PartialOrd<NP_Dec> for NP_Dec
[src]
Compare two NP_Dec
If the two exp
values are not identical, unexpected results may occur due to rounding.
use no_proto::pointer::dec::NP_Dec; let result = NP_Dec::new(203, 1) > NP_Dec::new(202, 1); assert_eq!(result, true); let result = NP_Dec::new(202, 1) < NP_Dec::new(203, 1); assert_eq!(result, true); let result = NP_Dec::new(20201, 2) > NP_Dec::new(202, 0); assert_eq!(result, true); let result = NP_Dec::new(20201, 2) == NP_Dec::new(2020100, 4); assert_eq!(result, true);
pub fn lt(&self, other: &NP_Dec) -> bool
[src]
pub fn le(&self, other: &NP_Dec) -> bool
[src]
pub fn gt(&self, other: &NP_Dec) -> bool
[src]
pub fn ge(&self, other: &NP_Dec) -> bool
[src]
pub fn partial_cmp(&self, other: &NP_Dec) -> Option<Ordering>
[src]
impl Sub<NP_Dec> for NP_Dec
[src]
type Output = NP_Dec
The resulting type after applying the -
operator.
pub fn sub(self, other: NP_Dec) -> Self::Output
[src]
impl SubAssign<NP_Dec> for NP_Dec
[src]
pub fn sub_assign(&mut self, other: NP_Dec)
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,