Value

Enum Value 

Source
pub enum Value {
    UnsignedInt(u64),
    UnsignedBigInt(u128),
    SignedInt(i64),
    SignedBigInt(i128),
    Float(f64),
}
Expand description

A numeric value.

Every calculation is parsed calculated as a common value type. This type can be concretely represented by one of a number of memory formats.

§Value Orders

The order of a value is jargon for its in-memory representation. The orders currently available are:

  1. u64
  2. u128
  3. i64
  4. i128
  5. f64

Note that in general, lower orders have a narrower scope and higher orders have a broader scope. This enables us to promote values to higher compatible orders as necessary.

§Promotion

It will sometimes be necessary to promote a value. The next order after a promotion depends on the value in question. It follows these rules:

  • u64 values are unconditionally promoted to u128 as that conversion is infallible

  • u128 values are promoted to the next order in sequence which can represent the type, according to whether or not it fits inside the type bounds.

    I.e. the value u64::MAX would be promoted to i128, skipping i64, as it could not be losslessly converted. The value i128::MAX + 1 would be promoted to f64, even though this will lose precision, because f64 can better approximate that overflow than i128 could.

  • i64 values are unconditionally promoted to i128 as that conversion is infallible.

  • i128 values are unconditionally promoted to f64 as that type can better approximate very large values.

  • f64 values remain f64.

§Parsing Rules

When parsing a value, each order is checked in sequence. The first value type which parses without error is used.

§Math Rules

When computing an expression, for each pair of values, this algorithm is applied:

  • the lower-order of the pair is promoted
  • if the two orders are still not equal, the previous step is repeated
  • once the two orders are equal, math is performed as normal.

§Equality and Comparison

Equality and comparison operations are defined on the logical values. This is to say that when testing equality or comparing values, they are promoted until they match, and then the appropriate calculation is performed.

For strict equality comparisons, use the strict_eq method. For strict ordering, use the strict_cmp method.

Variants§

§

UnsignedInt(u64)

§

UnsignedBigInt(u128)

§

SignedInt(i64)

§

SignedBigInt(i128)

§

Float(f64)

Implementations§

Source§

impl Value

Source

pub fn rotate_left(self, shift: impl Into<Value>) -> Result<Value, Error>

Compute this value left-shifted by other bits, wrapping the bits around.

Source

pub fn rotate_right(self, shift: impl Into<Value>) -> Result<Value, Error>

Compute this value right-shifted by other bits, wrapping the bits around.

Source§

impl Value

Source

pub fn strict_eq(self, other: Self) -> bool

Perform a strict equality comparison: this is equal if the values have equal value and order without promotion.

Source

pub fn strict_cmp(self, other: Self) -> Ordering

Compute a strict ordering: this orders first by the [Order][super::Order], then by value only if the orders match

Source§

impl Value

Source

pub fn trunc_div(self, other: impl Into<Self>) -> Self

Divide this value by another, flooring the result to the next lowest integer.

Source

pub fn pow(self, right: impl Into<Value>) -> Result<Value, Error>

Raise this value by another.

Source

pub fn abs(self) -> Value

Compute the absolute value of this value.

Source

pub fn ceil(self) -> Value

Compute the smallest integer greater than or equal to self.

Source

pub fn floor(self) -> Value

Compute the greatest integer less than or equal to self.

Source

pub fn round(self) -> Value

Round self to the nearest integer; halfway cases away from 0.0.

Source

pub fn sin(self) -> Value

Compute the sine of self.

Source

pub fn cos(self) -> Value

Compute the cosine of self.

Source

pub fn tan(self) -> Value

Compute the tangent of self.

Source

pub fn sinh(self) -> Value

Compute the hyperbolic sine of self.

Source

pub fn cosh(self) -> Value

Compute the hyperbolic cosine of self.

Source

pub fn tanh(self) -> Value

Compute the hyperbolic tangent of self.

Source

pub fn asin(self) -> Value

Compute the arcsine of self.

Source

pub fn acos(self) -> Value

Compute the arccosine of self.

Source

pub fn atan(self) -> Value

Compute the arctangent of self.

Source

pub fn asinh(self) -> Value

Compute the inverse hyperbolic sine of self.

Source

pub fn acosh(self) -> Value

Compute the inverse hyperbolic cosine of self.

Source

pub fn atanh(self) -> Value

Compute the inverse hyperbolic tangent of self.

Source

pub fn rad(self) -> Value

Convert self as degrees to radians.

Source

pub fn deg(self) -> Value

Convert self as radians to degrees.

Source

pub fn sqrt(self) -> Value

Determine the square root of self.

Source

pub fn cbrt(self) -> Value

Determine the cube root of self.

Source

pub fn log(self) -> Value

Determine the base-10 logarithm of self.

Source

pub fn lg(self) -> Value

Determine the base-2 logarithm of self

Source

pub fn ln(self) -> Value

Determine the base-e (natural) logarithm of self.

Source

pub fn exp(self) -> Value

Determine e**self

Source§

impl Value

Source

pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseValueError>

Parses an integer from a string slice with digits in a given base.

The string is expected to be an optional + or - sign followed by only digits. Leading and trailing non-digit characters (including whitespace) represent an error. Underscores (which are accepted in Rust literals) also represent an error.

This function panics if radix is not in 2..=36.

Source

pub fn parse_binary(s: &str) -> Result<Self, ParseValueError>

Parse a binary input without decimals.

Should succeed with or without a leading 0b.

Source

pub fn parse_octal(s: &str) -> Result<Self, ParseValueError>

Parse an octal input without decimals.

Should succeed with or without a leading 0o.

Source

pub fn parse_decimal(s: &str) -> Result<Self, ParseValueError>

Parse a decimal input which may or may not contain a decimal point.

Should succeed with or without a leading 0d.

Source

pub fn parse_hex(s: &str) -> Result<Self, ParseValueError>

Parse an octal input without decimals.

Should succeed with or without a leading 0o.

Source§

impl Value

Source

pub const PI: Self

Source

pub const E: Self

Trait Implementations§

Source§

impl<Rhs> Add<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Value

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Rhs) -> Value

Performs the + operation. Read more
Source§

impl<Rhs> AddAssign<Rhs> for Value
where Rhs: Into<Value>,

Source§

fn add_assign(&mut self, rhs: Rhs)

Performs the += operation. Read more
Source§

impl Binary for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Rhs> BitAnd<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Result<Value, Error>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Rhs) -> Self::Output

Performs the & operation. Read more
Source§

impl<Rhs> BitOr<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Result<Value, Error>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Rhs) -> Self::Output

Performs the | operation. Read more
Source§

impl<Rhs> BitXor<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Result<Value, Error>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Rhs) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Rhs> Div<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Value

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Rhs) -> Self::Output

Performs the / operation. Read more
Source§

impl<Rhs> DivAssign<Rhs> for Value
where Rhs: Into<Value>,

Source§

fn div_assign(&mut self, rhs: Rhs)

Performs the /= operation. Read more
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Value

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Value

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Value

Source§

type Err = ParseValueError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl IntoDiscriminant for Value

Source§

type Discriminant = Order

Enum listing the same variants as this enum but without any data fields
Source§

fn discriminant(&self) -> Self::Discriminant

Source§

impl LowerExp for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LowerHex for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Rhs> Mul<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Value

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rhs) -> Self::Output

Performs the * operation. Read more
Source§

impl<Rhs> MulAssign<Rhs> for Value
where Rhs: Into<Value>,

Source§

fn mul_assign(&mut self, rhs: Rhs)

Performs the *= operation. Read more
Source§

impl Neg for Value

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Not for Value

Source§

type Output = Result<Value, Error>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl Numeric for Value

Source§

type BinIter = Box<dyn Iterator<Item = char>>

Iterate over binary digits of this number. Read more
Source§

type OctIter = Box<dyn Iterator<Item = char>>

Iterate over octal digits of this number. Read more
Source§

type DecLeftIter = Box<dyn Iterator<Item = char>>

Iterate over decimal digits of this number which are >= 1. Read more
Source§

type DecRightIter = Box<dyn Iterator<Item = char>>

Iterate over decimal digits of this number which are < 1. Read more
Source§

type HexIter = Box<dyn Iterator<Item = char>>

Iterate over hexadecimal digits of this number, with letters as lowercase. Read more
Source§

fn binary(&self) -> Option<Self::BinIter>

Iterate over the binary digits of this number, from least to most significant. Read more
Source§

fn octal(&self) -> Option<Self::OctIter>

Iterate over the octal digits of this number, from least to most significant. Read more
Source§

fn decimal(&self) -> (Self::DecLeftIter, Option<Self::DecRightIter>)

Produce a pair of iterators over the decimal digits of this number. Read more
Source§

fn hex(&self) -> Option<Self::HexIter>

Iterate over the hexadecimal digits of this number, with letters as lowercase. Read more
Source§

fn is_negative(&self) -> bool

true when this value is less than 0.
Source§

impl Octal for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Value

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Rhs> Rem<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Value

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Rhs) -> Self::Output

Performs the % operation. Read more
Source§

impl<Rhs> RemAssign<Rhs> for Value
where Rhs: Into<Value>,

Source§

fn rem_assign(&mut self, rhs: Rhs)

Performs the %= operation. Read more
Source§

impl<Rhs> Shl<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Result<Value, Error>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: Rhs) -> Self::Output

Performs the << operation. Read more
Source§

impl<Rhs> Shr<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Result<Value, Error>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: Rhs) -> Self::Output

Performs the >> operation. Read more
Source§

impl<Rhs> Sub<Rhs> for Value
where Rhs: Into<Value>,

Source§

type Output = Value

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Rhs) -> Self::Output

Performs the - operation. Read more
Source§

impl<Rhs> SubAssign<Rhs> for Value
where Rhs: Into<Value>,

Source§

fn sub_assign(&mut self, rhs: Rhs)

Performs the -= operation. Read more
Source§

impl TryFrom<Value> for f64

Source§

type Error = TryIntoError<Value>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, TryIntoError<Value>>

Performs the conversion.
Source§

impl TryFrom<Value> for i128

Source§

type Error = TryIntoError<Value>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, TryIntoError<Value>>

Performs the conversion.
Source§

impl TryFrom<Value> for i64

Source§

type Error = TryIntoError<Value>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, TryIntoError<Value>>

Performs the conversion.
Source§

impl TryFrom<Value> for u128

Source§

type Error = TryIntoError<Value>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, TryIntoError<Value>>

Performs the conversion.
Source§

impl TryFrom<Value> for u64

Source§

type Error = TryIntoError<Value>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, TryIntoError<Value>>

Performs the conversion.
Source§

impl UpperExp for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl UpperHex for Value

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Value

Source§

impl Eq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,