pub struct Decimal {
pub sign: i8,
pub layer: i64,
pub mag: f64,
}Expand description
A Decimal number that can represent numbers as large as 10^^1e308 and as ‘small’ as 10^-(10^^1e308).
Fields§
§sign: i8Sign of the Decimal. 1 for positive, -1 for negative.
layer: i64Layer of magnitude.
mag: f64Magnitude of the Decimal.
Implementations§
Source§impl Decimal
impl Decimal
Sourcepub fn new(sign: i8, layer: i64, mag: f64) -> Decimal
pub fn new(sign: i8, layer: i64, mag: f64) -> Decimal
Creates a new Decimal
This does not normalize the Decimal, use Decimal::from_components for automatic normalization.
Sourcepub fn set_mantissa(&mut self, m: f64)
pub fn set_mantissa(&mut self, m: f64)
Sets the mantissa of the Decimal
Sourcepub fn set_exponent(&mut self, e: f64)
pub fn set_exponent(&mut self, e: f64)
Sets the exponent of the Decimal
Sourcepub fn from_components(sign: i8, layer: i64, mag: f64) -> Decimal
pub fn from_components(sign: i8, layer: i64, mag: f64) -> Decimal
Creates a Decimal from a sign, a layer and a magnitude
This function normalizes the inputs
Sourcepub fn from_components_no_normalize(sign: i8, layer: i64, mag: f64) -> Decimal
pub fn from_components_no_normalize(sign: i8, layer: i64, mag: f64) -> Decimal
Creates a Decimal from a sign, a layer and a magnitude
This function does not normalize the inputs
Sourcepub fn from_mantissa_exponent(m: f64, e: f64) -> Decimal
pub fn from_mantissa_exponent(m: f64, e: f64) -> Decimal
Creates a Decimal from a mantissa and an exponent
This function normalizes the inputs
Sourcepub fn from_mantissa_exponent_no_normalize(m: f64, e: f64) -> Decimal
pub fn from_mantissa_exponent_no_normalize(m: f64, e: f64) -> Decimal
Creates a Decimal from a mantissa and an exponent
This function does not normalize the inputs
Sourcepub fn from_number(n: f64) -> Decimal
pub fn from_number(n: f64) -> Decimal
Creates a Decimal from a number (f64)
Sourcepub fn normalize(&mut self) -> Decimal
pub fn normalize(&mut self) -> Decimal
Normalizes the Decimal as follows:
- Whenever we are partially 0 (sign is 0 or mag and layer is 0), make it fully 0.
- Whenever we are at or hit layer 0, extract sign from negative mag.
- If layer === 0 and mag < FIRST_NEG_LAYER (1/9e15), shift to ‘first negative layer’ (add layer, log10 mag).
- While abs(mag) > EXP_LIMIT (9e15), layer += 1, mag = maglog10(mag).
- While abs(mag) < LAYER_DOWN (15.954) and layer > 0, layer -= 1, mag = pow(10, mag).
- When we’re done, all of the following should be true OR one of the numbers is not finite OR layer is not an integer (error state):
- Any 0 is totally zero (0, 0, 0).
- Anything layer 0 has mag 0 OR mag > 1/9e15 and < 9e15.
- Anything layer 1 or higher has abs(mag) >= 15.954 and < 9e15.
- We will assume in calculations that all Decimals are either erroneous or satisfy these criteria. (Otherwise: Garbage in, garbage out.)
Sourcepub fn set_from_components(&mut self, sign: i8, layer: i64, mag: f64) -> Decimal
pub fn set_from_components(&mut self, sign: i8, layer: i64, mag: f64) -> Decimal
Sets the components of the Decimal from a sign, a layer and a magnitude
This function normalizes the inputs
Sourcepub fn set_from_components_no_normalize(
&mut self,
sign: i8,
layer: i64,
mag: f64,
) -> Decimal
pub fn set_from_components_no_normalize( &mut self, sign: i8, layer: i64, mag: f64, ) -> Decimal
Sets the components of the Decimal from a sign, a layer and a magnitude
This function does not normalize the inputs
Sourcepub fn set_from_mantissa_exponent(&mut self, m: f64, e: f64) -> Decimal
pub fn set_from_mantissa_exponent(&mut self, m: f64, e: f64) -> Decimal
Sets the components of the Decimal from a mantissa and an exponent
This function normalizes the inputs
Sourcepub fn set_from_mantissa_exponent_no_normalize(
&mut self,
m: f64,
e: f64,
) -> Decimal
pub fn set_from_mantissa_exponent_no_normalize( &mut self, m: f64, e: f64, ) -> Decimal
Sets the components of the Decimal from a mantissa and an exponent
This function does not normalize the inputs
Sourcepub fn set_from_number(&mut self, n: f64) -> Decimal
pub fn set_from_number(&mut self, n: f64) -> Decimal
Sets the components of the Decimal from a number (f64)
Sourcepub fn mantissa_with_decimal_places(&self, places: i32) -> f64
pub fn mantissa_with_decimal_places(&self, places: i32) -> f64
Returns the mantissa with the specified amount of decimal places
Sourcepub fn magnitude_with_decimal_places(&self, places: i32) -> f64
pub fn magnitude_with_decimal_places(&self, places: i32) -> f64
Returns the magnitude with the specified amount of decimal places
Sourcepub fn to_fixed(&self, places: usize) -> String
pub fn to_fixed(&self, places: usize) -> String
Returns the Decimal as a String with the specified amount of decimal places
Sourcepub fn to_precision(&self, places: usize) -> String
pub fn to_precision(&self, places: usize) -> String
Returns the Decimal as a String with the specified amount of precision.
If the amount of decimal places is larger than that the exponent, this will return a fixed representation of the number.
Otherwise, this will return a scientific representation of the number.
Sourcepub fn to_string_with_decimal_places(
&self,
places: usize,
e_lower: Option<bool>,
) -> String
pub fn to_string_with_decimal_places( &self, places: usize, e_lower: Option<bool>, ) -> String
Returns the Decimal as a String with the specified amount of precision.
This follows more rules than to_precision.
If the layer of the Decimal is 0 and the magnitude is less than 1e21 and larger than 1e-7 (or when the magnitude is 0), this will return a fixed representation of the number. If the layer is 0, a scientific representation of the number will be returned.
If the layer is 1, a scientific representation of the number will be returned.
Otherwise, a scientific representation with multiple es will be returned.
Sourcepub fn maximum() -> Decimal
pub fn maximum() -> Decimal
Returns the largest safe Decimal that can be represented from an f64
Sourcepub fn minimum() -> Decimal
pub fn minimum() -> Decimal
Returns the smallest safe Decimal that can be represented from an f64
Sourcepub fn ceil(&self) -> Decimal
pub fn ceil(&self) -> Decimal
Returns the smallest Decimal greater than or equal to the Decimal.
Sourcepub fn cmpabs(&self, rhs: &Decimal) -> i8
pub fn cmpabs(&self, rhs: &Decimal) -> i8
Compares the absolute value of the Decimal to the absolute value of the other Decimal
Sourcepub fn maxabs(&self, rhs: Decimal) -> Decimal
pub fn maxabs(&self, rhs: Decimal) -> Decimal
Compares the absolute value of the Decimal to the absolute value of the other Decimal and returns the bigger one
Sourcepub fn minabs(&self, rhs: Decimal) -> Decimal
pub fn minabs(&self, rhs: Decimal) -> Decimal
Compares the absolute value of the Decimal to the absolute value of the other Decimal and returns the smaller one
Sourcepub fn clamp(&self, min: Decimal, max: Decimal) -> Decimal
pub fn clamp(&self, min: Decimal, max: Decimal) -> Decimal
Clamps the Decimal to the given range
Sourcepub fn eq_tolerance(&self, other: &Decimal, tolerance: f64) -> bool
pub fn eq_tolerance(&self, other: &Decimal, tolerance: f64) -> bool
Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will count as equal.
Default tolerance is 1e-7
Sourcepub fn pow(self, exp: Decimal) -> Decimal
pub fn pow(self, exp: Decimal) -> Decimal
Returns the Decimal to the power of the given exponent
Sourcepub fn ln_gamma(&self) -> Decimal
pub fn ln_gamma(&self) -> Decimal
Returns the natural logarithm of the gamma function of the Decimal
Sourcepub fn tetrate(&self, height: Option<f64>, payload: Option<Decimal>) -> Decimal
pub fn tetrate(&self, height: Option<f64>, payload: Option<Decimal>) -> Decimal
Tetrates the Decimal to the given height.
Source: https://andydude.github.io/tetration/archives/tetration2/ident.html
Sourcepub fn iteratedexp(
&self,
height: Option<f64>,
payload: Option<Decimal>,
) -> Decimal
pub fn iteratedexp( &self, height: Option<f64>, payload: Option<Decimal>, ) -> Decimal
Returns the Decimal, iteratively exponentiated
Equates to tetrating to the same height.
Sourcepub fn iteratedlog(&self, base: Decimal, times: f64) -> Decimal
pub fn iteratedlog(&self, base: Decimal, times: f64) -> Decimal
Iterated log: The result of applying log(base) ‘times’ times in a row. Approximately equal to subtratcting (times) from the number’s slo representation. Equates to tetrating to a negative height.
Sourcepub fn slog(&self, base_opt: Option<Decimal>) -> Decimal
pub fn slog(&self, base_opt: Option<Decimal>) -> Decimal
Returns the super-logarithm of the Decimal
Sourcepub fn layer_add_10(&self, diff: Decimal) -> Decimal
pub fn layer_add_10(&self, diff: Decimal) -> Decimal
Adds or removes layers from a Decimal using linear approximation
Sourcepub fn layer_add(&self, diff: f64, base: Decimal) -> Decimal
pub fn layer_add(&self, diff: f64, base: Decimal) -> Decimal
Adds diff to the Decimal’s slog(base) representation
Sourcepub fn lambertw(&self) -> Result<Decimal, BreakEternityError>
pub fn lambertw(&self) -> Result<Decimal, BreakEternityError>
Returns the product logarithm of the Decimal
Sourcepub fn ssqrt(&self) -> Decimal
pub fn ssqrt(&self) -> Decimal
Returns the super square root of the Decimal
Essentially “what number, tetrated to height 2, equals this?”
Trait Implementations§
Source§impl AddAssign<f32> for Decimal
impl AddAssign<f32> for Decimal
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
+= operation. Read moreSource§impl AddAssign<f64> for Decimal
impl AddAssign<f64> for Decimal
Source§fn add_assign(&mut self, rhs: f64)
fn add_assign(&mut self, rhs: f64)
+= operation. Read moreSource§impl AddAssign<i16> for Decimal
impl AddAssign<i16> for Decimal
Source§fn add_assign(&mut self, rhs: i16)
fn add_assign(&mut self, rhs: i16)
+= operation. Read moreSource§impl AddAssign<i32> for Decimal
impl AddAssign<i32> for Decimal
Source§fn add_assign(&mut self, rhs: i32)
fn add_assign(&mut self, rhs: i32)
+= operation. Read moreSource§impl AddAssign<i64> for Decimal
impl AddAssign<i64> for Decimal
Source§fn add_assign(&mut self, rhs: i64)
fn add_assign(&mut self, rhs: i64)
+= operation. Read moreSource§impl AddAssign<i8> for Decimal
impl AddAssign<i8> for Decimal
Source§fn add_assign(&mut self, rhs: i8)
fn add_assign(&mut self, rhs: i8)
+= operation. Read moreSource§impl AddAssign<u16> for Decimal
impl AddAssign<u16> for Decimal
Source§fn add_assign(&mut self, rhs: u16)
fn add_assign(&mut self, rhs: u16)
+= operation. Read moreSource§impl AddAssign<u32> for Decimal
impl AddAssign<u32> for Decimal
Source§fn add_assign(&mut self, rhs: u32)
fn add_assign(&mut self, rhs: u32)
+= operation. Read moreSource§impl AddAssign<u64> for Decimal
impl AddAssign<u64> for Decimal
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+= operation. Read moreSource§impl AddAssign<u8> for Decimal
impl AddAssign<u8> for Decimal
Source§fn add_assign(&mut self, rhs: u8)
fn add_assign(&mut self, rhs: u8)
+= operation. Read moreSource§impl AddAssign for Decimal
impl AddAssign for Decimal
Source§fn add_assign(&mut self, rhs: Decimal)
fn add_assign(&mut self, rhs: Decimal)
+= operation. Read moreSource§impl DivAssign<f32> for Decimal
impl DivAssign<f32> for Decimal
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl DivAssign<f64> for Decimal
impl DivAssign<f64> for Decimal
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/= operation. Read moreSource§impl DivAssign<i16> for Decimal
impl DivAssign<i16> for Decimal
Source§fn div_assign(&mut self, rhs: i16)
fn div_assign(&mut self, rhs: i16)
/= operation. Read moreSource§impl DivAssign<i32> for Decimal
impl DivAssign<i32> for Decimal
Source§fn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
/= operation. Read moreSource§impl DivAssign<i64> for Decimal
impl DivAssign<i64> for Decimal
Source§fn div_assign(&mut self, rhs: i64)
fn div_assign(&mut self, rhs: i64)
/= operation. Read moreSource§impl DivAssign<i8> for Decimal
impl DivAssign<i8> for Decimal
Source§fn div_assign(&mut self, rhs: i8)
fn div_assign(&mut self, rhs: i8)
/= operation. Read moreSource§impl DivAssign<u16> for Decimal
impl DivAssign<u16> for Decimal
Source§fn div_assign(&mut self, rhs: u16)
fn div_assign(&mut self, rhs: u16)
/= operation. Read moreSource§impl DivAssign<u32> for Decimal
impl DivAssign<u32> for Decimal
Source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/= operation. Read moreSource§impl DivAssign<u64> for Decimal
impl DivAssign<u64> for Decimal
Source§fn div_assign(&mut self, rhs: u64)
fn div_assign(&mut self, rhs: u64)
/= operation. Read moreSource§impl DivAssign<u8> for Decimal
impl DivAssign<u8> for Decimal
Source§fn div_assign(&mut self, rhs: u8)
fn div_assign(&mut self, rhs: u8)
/= operation. Read moreSource§impl DivAssign for Decimal
impl DivAssign for Decimal
Source§fn div_assign(&mut self, rhs: Decimal)
fn div_assign(&mut self, rhs: Decimal)
/= operation. Read moreSource§impl MulAssign<f32> for Decimal
impl MulAssign<f32> for Decimal
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl MulAssign<f64> for Decimal
impl MulAssign<f64> for Decimal
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*= operation. Read moreSource§impl MulAssign<i16> for Decimal
impl MulAssign<i16> for Decimal
Source§fn mul_assign(&mut self, rhs: i16)
fn mul_assign(&mut self, rhs: i16)
*= operation. Read moreSource§impl MulAssign<i32> for Decimal
impl MulAssign<i32> for Decimal
Source§fn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
*= operation. Read moreSource§impl MulAssign<i64> for Decimal
impl MulAssign<i64> for Decimal
Source§fn mul_assign(&mut self, rhs: i64)
fn mul_assign(&mut self, rhs: i64)
*= operation. Read moreSource§impl MulAssign<i8> for Decimal
impl MulAssign<i8> for Decimal
Source§fn mul_assign(&mut self, rhs: i8)
fn mul_assign(&mut self, rhs: i8)
*= operation. Read moreSource§impl MulAssign<u16> for Decimal
impl MulAssign<u16> for Decimal
Source§fn mul_assign(&mut self, rhs: u16)
fn mul_assign(&mut self, rhs: u16)
*= operation. Read moreSource§impl MulAssign<u32> for Decimal
impl MulAssign<u32> for Decimal
Source§fn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
*= operation. Read moreSource§impl MulAssign<u64> for Decimal
impl MulAssign<u64> for Decimal
Source§fn mul_assign(&mut self, rhs: u64)
fn mul_assign(&mut self, rhs: u64)
*= operation. Read moreSource§impl MulAssign<u8> for Decimal
impl MulAssign<u8> for Decimal
Source§fn mul_assign(&mut self, rhs: u8)
fn mul_assign(&mut self, rhs: u8)
*= operation. Read moreSource§impl MulAssign for Decimal
impl MulAssign for Decimal
Source§fn mul_assign(&mut self, rhs: Decimal)
fn mul_assign(&mut self, rhs: Decimal)
*= operation. Read moreSource§impl Ord for Decimal
impl Ord for Decimal
Source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
Source§impl RemAssign<f32> for Decimal
impl RemAssign<f32> for Decimal
Source§fn rem_assign(&mut self, rhs: f32)
fn rem_assign(&mut self, rhs: f32)
%= operation. Read moreSource§impl RemAssign<f64> for Decimal
impl RemAssign<f64> for Decimal
Source§fn rem_assign(&mut self, rhs: f64)
fn rem_assign(&mut self, rhs: f64)
%= operation. Read moreSource§impl RemAssign<i16> for Decimal
impl RemAssign<i16> for Decimal
Source§fn rem_assign(&mut self, rhs: i16)
fn rem_assign(&mut self, rhs: i16)
%= operation. Read moreSource§impl RemAssign<i32> for Decimal
impl RemAssign<i32> for Decimal
Source§fn rem_assign(&mut self, rhs: i32)
fn rem_assign(&mut self, rhs: i32)
%= operation. Read moreSource§impl RemAssign<i64> for Decimal
impl RemAssign<i64> for Decimal
Source§fn rem_assign(&mut self, rhs: i64)
fn rem_assign(&mut self, rhs: i64)
%= operation. Read moreSource§impl RemAssign<i8> for Decimal
impl RemAssign<i8> for Decimal
Source§fn rem_assign(&mut self, rhs: i8)
fn rem_assign(&mut self, rhs: i8)
%= operation. Read moreSource§impl RemAssign<u16> for Decimal
impl RemAssign<u16> for Decimal
Source§fn rem_assign(&mut self, rhs: u16)
fn rem_assign(&mut self, rhs: u16)
%= operation. Read moreSource§impl RemAssign<u32> for Decimal
impl RemAssign<u32> for Decimal
Source§fn rem_assign(&mut self, rhs: u32)
fn rem_assign(&mut self, rhs: u32)
%= operation. Read moreSource§impl RemAssign<u64> for Decimal
impl RemAssign<u64> for Decimal
Source§fn rem_assign(&mut self, rhs: u64)
fn rem_assign(&mut self, rhs: u64)
%= operation. Read moreSource§impl RemAssign<u8> for Decimal
impl RemAssign<u8> for Decimal
Source§fn rem_assign(&mut self, rhs: u8)
fn rem_assign(&mut self, rhs: u8)
%= operation. Read moreSource§impl RemAssign for Decimal
impl RemAssign for Decimal
Source§fn rem_assign(&mut self, rhs: Decimal)
fn rem_assign(&mut self, rhs: Decimal)
%= operation. Read moreSource§impl SubAssign<f32> for Decimal
impl SubAssign<f32> for Decimal
Source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
-= operation. Read moreSource§impl SubAssign<f64> for Decimal
impl SubAssign<f64> for Decimal
Source§fn sub_assign(&mut self, rhs: f64)
fn sub_assign(&mut self, rhs: f64)
-= operation. Read moreSource§impl SubAssign<i16> for Decimal
impl SubAssign<i16> for Decimal
Source§fn sub_assign(&mut self, rhs: i16)
fn sub_assign(&mut self, rhs: i16)
-= operation. Read moreSource§impl SubAssign<i32> for Decimal
impl SubAssign<i32> for Decimal
Source§fn sub_assign(&mut self, rhs: i32)
fn sub_assign(&mut self, rhs: i32)
-= operation. Read moreSource§impl SubAssign<i64> for Decimal
impl SubAssign<i64> for Decimal
Source§fn sub_assign(&mut self, rhs: i64)
fn sub_assign(&mut self, rhs: i64)
-= operation. Read moreSource§impl SubAssign<i8> for Decimal
impl SubAssign<i8> for Decimal
Source§fn sub_assign(&mut self, rhs: i8)
fn sub_assign(&mut self, rhs: i8)
-= operation. Read moreSource§impl SubAssign<u16> for Decimal
impl SubAssign<u16> for Decimal
Source§fn sub_assign(&mut self, rhs: u16)
fn sub_assign(&mut self, rhs: u16)
-= operation. Read moreSource§impl SubAssign<u32> for Decimal
impl SubAssign<u32> for Decimal
Source§fn sub_assign(&mut self, rhs: u32)
fn sub_assign(&mut self, rhs: u32)
-= operation. Read moreSource§impl SubAssign<u64> for Decimal
impl SubAssign<u64> for Decimal
Source§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
-= operation. Read moreSource§impl SubAssign<u8> for Decimal
impl SubAssign<u8> for Decimal
Source§fn sub_assign(&mut self, rhs: u8)
fn sub_assign(&mut self, rhs: u8)
-= operation. Read moreSource§impl SubAssign for Decimal
impl SubAssign for Decimal
Source§fn sub_assign(&mut self, rhs: Decimal)
fn sub_assign(&mut self, rhs: Decimal)
-= operation. Read more