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
impl Scalar
Sourcepub fn parse(dtype: DType, text: &str) -> Result<Self, DataError>
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.
Sourcepub fn from_bits(dtype: DType, bits: u128) -> Result<Self, DataError>
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.
Sourcepub fn from_signed(dtype: DType, value: i128) -> Result<Self, DataError>
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.
Sourcepub fn from_unsigned(dtype: DType, value: u128) -> Result<Self, DataError>
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.
Sourcepub fn as_i128(self) -> Option<i128>
pub fn as_i128(self) -> Option<i128>
Signed integer value, without converting any other representation.
Sourcepub fn as_u128(self) -> Option<u128>
pub fn as_u128(self) -> Option<u128>
Unsigned integer value, without converting any other representation.
Sourcepub fn to_f64(self) -> Result<f64, DataError>
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.
Sourcepub fn convert(self, dtype: DType) -> Result<Self, DataError>
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.
Sourcepub fn neg(&self) -> Result<Self, DataError>
pub fn neg(&self) -> Result<Self, DataError>
Negates a value with checked integer overflow.
§Errors
Rejects the signed minimum and nonzero unsigned values.
Sourcepub fn binary(self, operation: BinaryOp, rhs: Self) -> Result<Self, DataError>
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.