Skip to main content

Scalar

Struct Scalar 

Source
pub struct Scalar { /* private fields */ }
Expand description

One finite numeric value with an explicit declared representation.

The private bits are validated at construction. Integers never pass through floating point, and binary128 never passes through binary64. PartialEq compares numeric values of matching types, so positive and negative float zero compare equal. Self::bits preserves their distinct representations.

Implementations§

Source§

impl Scalar

Source

pub fn parse(dtype: DType, text: &str) -> Result<Self, DataError>

Parses decimal text directly at the requested precision.

Float literals are rounded once with ties-to-even; unlike Self::convert, decimal parsing accepts normal representational rounding (for example 0.1). Text may have a sign, decimal point, and decimal exponent for floats.

§Errors

Rejects malformed or overlong text, out-of-range integers, and nonfinite floats.

Source

pub fn from_bits(dtype: DType, bits: u128) -> Result<Self, DataError>

Creates a finite value from unsigned representation bits.

Signed integers use two’s complement in exactly dtype.bit_width() bits; high bits must be zero even for negative integers.

§Errors

Rejects bits outside the declared width and nonfinite float encodings.

Source

pub fn from_signed(dtype: DType, value: i128) -> Result<Self, DataError>

Creates a signed integer after validating the declared range.

§Errors

Rejects non-signed types and values outside their exact integer range.

Source

pub fn from_unsigned(dtype: DType, value: u128) -> Result<Self, DataError>

Creates an unsigned integer after validating the declared range.

§Errors

Rejects signed/float types and values outside the exact unsigned range.

Source

pub const fn zero(dtype: DType) -> Self

Positive zero in any supported representation.

Source

pub const fn dtype(self) -> DType

Declared numeric type.

Source

pub const fn bits(self) -> u128

Representation bits with all unused high bits zero.

Source

pub fn as_i128(self) -> Option<i128>

Signed integer value, without converting any other representation.

Source

pub fn as_u128(self) -> Option<u128>

Unsigned integer value, without converting any other representation.

Source

pub fn to_f64(self) -> Result<f64, DataError>

Converts exactly to a native binary64 value for a host boundary.

§Errors

Rejects any value not representable exactly in binary64.

Source

pub fn convert(self, dtype: DType) -> Result<Self, DataError>

Converts only when the exact value and signed-zero information survive.

§Errors

Rejects out-of-range, fractional, or precision-losing conversions.

Source

pub fn neg(&self) -> Result<Self, DataError>

Negates a value with checked integer overflow.

§Errors

Rejects the signed minimum and nonzero unsigned values.

Source

pub fn binary(self, operation: BinaryOp, rhs: Self) -> Result<Self, DataError>

Evaluates one checked operation at the operands’ declared precision.

Floating-point rounding and underflow follow IEEE ties-to-even. Integer overflow and nonfinite floating-point results are errors.

§Errors

Rejects mixed types, zero divisors, overflow, and nonfinite results.

Source

pub fn compare(self, rhs: Self) -> Result<Ordering, DataError>

Compares numeric values of identical declared types.

§Errors

Returns DataError::TypeMismatch for different declared types.

Trait Implementations§

Source§

impl Add for Scalar

Source§

type Output = Result<Scalar, DataError>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Scalar

Source§

fn clone(&self) -> Scalar

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Scalar

Source§

impl Debug for Scalar

Source§

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

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

impl<'de> Deserialize<'de> for Scalar

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Scalar

Source§

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

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

impl Div for Scalar

Source§

type Output = Result<Scalar, DataError>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Eq for Scalar

Source§

impl Mul for Scalar

Source§

type Output = Result<Scalar, DataError>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Scalar

Source§

type Output = Result<Scalar, DataError>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Scalar

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Rem for Scalar

Source§

type Output = Result<Scalar, DataError>

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl Serialize for Scalar

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for Scalar

Source§

type Output = Result<Scalar, DataError>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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.