pub struct NonNegativeRealScalar<RealType: RealScalar>(/* private fields */);Expand description
Type-safe wrapper for non-negative real scalar values.
NonNegativeRealScalar<T> guarantees that wrapped values are greater than or equal to zero.
Zero is valid for this type. For values that must be strictly positive, use PositiveRealScalar.
§Mathematical Definition
NonNegativeRealScalar<T> = { x ∈ T : x ≥ 0 }This is the set of non-negative real numbers ℝ₀⁺, which includes zero.
§Use Cases
- Distances (can be zero when comparing a value to itself)
- Absolute values
- Magnitudes
- Any quantity that is mathematically required to be ≥ 0
§Examples
§Basic Usage
use num_valid::{*, scalars::*};
use try_create::TryNew;
// Zero is valid
let zero = NonNegativeRealScalar::try_new(0.0_f64).unwrap();
assert_eq!(zero.as_raw_scalar_ref(), &0.0);
// Positive values are valid
let positive = NonNegativeRealScalar::try_new(5.0_f64).unwrap();
// Negative values are rejected
assert!(matches!(
NonNegativeRealScalar::try_new(-1.0_f64),
Err(ErrorsNonNegativeRealScalar::NegativeValue { .. })
));§Use Case: Computing Distances
use num_valid::{*, scalars::NonNegativeRealScalar};
use try_create::TryNew;
fn distance(a: f64, b: f64) -> NonNegativeRealScalar<f64> {
NonNegativeRealScalar::try_new((a - b).abs()).unwrap()
}
// Different points
let d1 = distance(0.0, 5.0);
assert_eq!(*d1.as_raw_scalar_ref(), 5.0);
// Same point (zero distance is valid!)
let d2 = distance(3.0, 3.0);
assert_eq!(d2.as_raw_scalar_ref(), &0.0);§Algebraic and Ordering Operations
NonNegativeRealScalar supports:
- Addition: Sum of non-negative values is non-negative
- Multiplication: Product of non-negative values is non-negative
- Integer powers: Raising non-negative to any integer exponent yields non-negative
- Additive identity (
Zero): For neutral addition operations - Multiplicative identity (
One): For neutral multiplication operations - Comparison (
Max,Min): Ordering and selection helpers
use num::{One, Zero};
use num_valid::{
*,
functions::{Max, Min, Pow},
scalars::NonNegativeRealScalar,
};
use try_create::TryNew;
let a = NonNegativeRealScalar::try_new(1.25_f64).unwrap();
let b = NonNegativeRealScalar::try_new(2.75_f64).unwrap();
// Add preserves non-negativity for valid operands.
let sum = a.clone() + &b;
assert_eq!(*sum.as_raw_scalar_ref(), 4.0);
// Multiply preserves non-negativity
let product = a * b;
assert!(*product.as_raw_scalar_ref() > 0.0);
// Integer powers preserve non-negativity
let base = NonNegativeRealScalar::try_new(2.0_f64).unwrap();
let squared = base.clone().pow(2u32);
assert_eq!(*squared.as_raw_scalar_ref(), 4.0);
// Zero is the additive identity.
let z = NonNegativeRealScalar::<f64>::zero();
assert!(z.is_zero());
assert_eq!(*(sum + z).as_raw_scalar_ref(), 4.0);
// One is the multiplicative identity.
let one = NonNegativeRealScalar::<f64>::one();
let result = base.clone() * one;
assert_eq!(*result.as_raw_scalar_ref(), 2.0);
let x = NonNegativeRealScalar::try_new(1.0_f64).unwrap();
let y = NonNegativeRealScalar::try_new(3.0_f64).unwrap();
assert_eq!(*Max::max_by_ref(&x, &y).as_raw_scalar_ref(), 3.0);
assert_eq!(*Min::min_by_value(x, y).as_raw_scalar_ref(), 1.0);Implementations§
Source§impl<RealType: RealScalar> NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> NonNegativeRealScalar<RealType>
Sourcepub fn into_inner(self) -> RealType
pub fn into_inner(self) -> RealType
Consumes the struct and returns the inner value.
Source§impl<RealType: RealScalar> NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> NonNegativeRealScalar<RealType>
Sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
Computes the square root of this non-negative scalar.
Since the input is guaranteed to be non-negative, the result is always defined and remains non-negative.
§Examples
use num_valid::{*, scalars::NonNegativeRealScalar};
use try_create::TryNew;
let value = NonNegativeRealScalar::try_new(4.0_f64).unwrap();
let sqrt = value.sqrt();
assert_eq!(sqrt.as_raw_scalar_ref(), &2.0);pub fn new(value: RealType) -> Self
Trait Implementations§
Source§impl<RealType: RealScalar> Add for NonNegativeRealScalar<RealType>
Implements additive composition for NonNegativeRealScalar.
impl<RealType: RealScalar> Add for NonNegativeRealScalar<RealType>
Implements additive composition for NonNegativeRealScalar.
Since both operands are guaranteed to be non-negative, their sum is also non-negative.
Source§impl<'a, RealType: RealScalar> Add<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements reference-based addition for NonNegativeRealScalar.
impl<'a, RealType: RealScalar> Add<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements reference-based addition for NonNegativeRealScalar.
This allows adding a reference to a non-negative scalar without consuming it. Since both operands are guaranteed to be non-negative, their sum is also non-negative.
Source§type Output = NonNegativeRealScalar<RealType>
type Output = NonNegativeRealScalar<RealType>
+ operator.Source§fn add(
self,
other: &'a NonNegativeRealScalar<RealType>,
) -> NonNegativeRealScalar<RealType>
fn add( self, other: &'a NonNegativeRealScalar<RealType>, ) -> NonNegativeRealScalar<RealType>
+ operation. Read moreSource§impl<'a, RealType: RealScalar> Add<&'a NonNegativeRealScalar<RealType>> for PositiveRealScalar<RealType>
Adds a NonNegativeRealScalar by reference to a PositiveRealScalar, yielding a PositiveRealScalar.
impl<'a, RealType: RealScalar> Add<&'a NonNegativeRealScalar<RealType>> for PositiveRealScalar<RealType>
Adds a NonNegativeRealScalar by reference to a PositiveRealScalar, yielding a PositiveRealScalar.
Since self is strictly positive (x > 0) and other is non-negative (y ≥ 0),
their sum is strictly positive: x + y > 0.
Source§type Output = PositiveRealScalar<RealType>
type Output = PositiveRealScalar<RealType>
+ operator.Source§fn add(
self,
other: &'a NonNegativeRealScalar<RealType>,
) -> PositiveRealScalar<RealType>
fn add( self, other: &'a NonNegativeRealScalar<RealType>, ) -> PositiveRealScalar<RealType>
+ operation. Read moreSource§impl<'a, RealType: RealScalar> Add<&'a PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Adds a PositiveRealScalar by reference to a NonNegativeRealScalar, yielding a PositiveRealScalar.
impl<'a, RealType: RealScalar> Add<&'a PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Adds a PositiveRealScalar by reference to a NonNegativeRealScalar, yielding a PositiveRealScalar.
Since other is strictly positive (x > 0) and self is non-negative (y ≥ 0),
their sum is strictly positive: x + y > 0.
Source§type Output = PositiveRealScalar<RealType>
type Output = PositiveRealScalar<RealType>
+ operator.Source§fn add(
self,
other: &'a PositiveRealScalar<RealType>,
) -> PositiveRealScalar<RealType>
fn add( self, other: &'a PositiveRealScalar<RealType>, ) -> PositiveRealScalar<RealType>
+ operation. Read moreSource§impl<RealType: RealScalar> Add<NonNegativeRealScalar<RealType>> for PositiveRealScalar<RealType>
Adds a NonNegativeRealScalar to a PositiveRealScalar, yielding a PositiveRealScalar.
impl<RealType: RealScalar> Add<NonNegativeRealScalar<RealType>> for PositiveRealScalar<RealType>
Adds a NonNegativeRealScalar to a PositiveRealScalar, yielding a PositiveRealScalar.
Since self is strictly positive (x > 0) and other is non-negative (y ≥ 0),
their sum is strictly positive: x + y > 0.
§Examples
use num_valid::{*, scalars::*};
use try_create::TryNew;
let pos = PositiveRealScalar::try_new(2.0_f64).unwrap();
let non_neg = NonNegativeRealScalar::try_new(3.0_f64).unwrap();
let result: PositiveRealScalar<f64> = pos + non_neg;
assert_eq!(result.as_raw_scalar_ref(), &5.0);Source§type Output = PositiveRealScalar<RealType>
type Output = PositiveRealScalar<RealType>
+ operator.Source§fn add(
self,
other: NonNegativeRealScalar<RealType>,
) -> PositiveRealScalar<RealType>
fn add( self, other: NonNegativeRealScalar<RealType>, ) -> PositiveRealScalar<RealType>
+ operation. Read moreSource§impl<RealType: RealScalar> Add<PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Adds a PositiveRealScalar to a NonNegativeRealScalar, yielding a PositiveRealScalar.
impl<RealType: RealScalar> Add<PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Adds a PositiveRealScalar to a NonNegativeRealScalar, yielding a PositiveRealScalar.
Since other is strictly positive (x > 0) and self is non-negative (y ≥ 0),
their sum is strictly positive: x + y > 0.
§Examples
use num_valid::{*, scalars::*};
use try_create::TryNew;
let non_neg = NonNegativeRealScalar::try_new(0.0_f64).unwrap(); // zero!
let pos = PositiveRealScalar::try_new(5.0_f64).unwrap();
let result: PositiveRealScalar<f64> = non_neg + pos;
assert_eq!(result.as_raw_scalar_ref(), &5.0);Source§type Output = PositiveRealScalar<RealType>
type Output = PositiveRealScalar<RealType>
+ operator.Source§fn add(
self,
other: PositiveRealScalar<RealType>,
) -> PositiveRealScalar<RealType>
fn add( self, other: PositiveRealScalar<RealType>, ) -> PositiveRealScalar<RealType>
+ operation. Read moreSource§impl<RealType: RealScalar> AddAssign for NonNegativeRealScalar<RealType>
Implements in-place addition for NonNegativeRealScalar by value.
impl<RealType: RealScalar> AddAssign for NonNegativeRealScalar<RealType>
Implements in-place addition for NonNegativeRealScalar by value.
This allows adding a non-negative scalar value to self.
Source§fn add_assign(&mut self, other: NonNegativeRealScalar<RealType>)
fn add_assign(&mut self, other: NonNegativeRealScalar<RealType>)
+= operation. Read moreSource§impl<'a, RealType: RealScalar> AddAssign<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements in-place reference-based addition for NonNegativeRealScalar.
impl<'a, RealType: RealScalar> AddAssign<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements in-place reference-based addition for NonNegativeRealScalar.
This allows adding a reference to a non-negative scalar to self without consuming self.
Source§fn add_assign(&mut self, other: &'a NonNegativeRealScalar<RealType>)
fn add_assign(&mut self, other: &'a NonNegativeRealScalar<RealType>)
+= operation. Read moreSource§impl<RealType: RealScalar> AsRef<NonNegativeRealScalar<RealType>> for AbsoluteTolerance<RealType>
impl<RealType: RealScalar> AsRef<NonNegativeRealScalar<RealType>> for AbsoluteTolerance<RealType>
Source§fn as_ref(&self) -> &NonNegativeRealScalar<RealType>
fn as_ref(&self) -> &NonNegativeRealScalar<RealType>
Source§impl<RealType: RealScalar> AsRef<NonNegativeRealScalar<RealType>> for RelativeTolerance<RealType>
impl<RealType: RealScalar> AsRef<NonNegativeRealScalar<RealType>> for RelativeTolerance<RealType>
Source§fn as_ref(&self) -> &NonNegativeRealScalar<RealType>
fn as_ref(&self) -> &NonNegativeRealScalar<RealType>
Source§impl<RealType: RealScalar> AsRef<RealType> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> AsRef<RealType> for NonNegativeRealScalar<RealType>
Source§impl<RealType: Clone + RealScalar> Clone for NonNegativeRealScalar<RealType>
impl<RealType: Clone + RealScalar> Clone for NonNegativeRealScalar<RealType>
Source§fn clone(&self) -> NonNegativeRealScalar<RealType>
fn clone(&self) -> NonNegativeRealScalar<RealType>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<RealType: Debug + RealScalar> Debug for NonNegativeRealScalar<RealType>
impl<RealType: Debug + RealScalar> Debug for NonNegativeRealScalar<RealType>
Source§impl<'de, RealType> Deserialize<'de> for NonNegativeRealScalar<RealType>where
RealType: for<'a> Deserialize<'a> + RealScalar,
impl<'de, RealType> Deserialize<'de> for NonNegativeRealScalar<RealType>where
RealType: for<'a> Deserialize<'a> + RealScalar,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<RealType> Display for NonNegativeRealScalar<RealType>where
RealType: Display + RealScalar,
impl<RealType> Display for NonNegativeRealScalar<RealType>where
RealType: Display + RealScalar,
Source§impl<RealType: RealScalar> From<PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Converts a PositiveRealScalar<T> to a NonNegativeRealScalar<T>.
impl<RealType: RealScalar> From<PositiveRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Converts a PositiveRealScalar<T> to a NonNegativeRealScalar<T>.
This conversion is mathematically valid because every positive number (x > 0) is also non-negative (x ≥ 0). The conversion is infallible and zero-cost.
§Examples
use num_valid::{*, scalars::*};
use try_create::TryNew;
let positive = PositiveRealScalar::try_new(5.0_f64).unwrap();
let non_negative: NonNegativeRealScalar<f64> = positive.into();
assert_eq!(non_negative.as_raw_scalar_ref(), &5.0);Source§fn from(positive: PositiveRealScalar<RealType>) -> Self
fn from(positive: PositiveRealScalar<RealType>) -> Self
Source§impl<RealType: RealScalar> IntoInner for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> IntoInner for NonNegativeRealScalar<RealType>
Source§impl<RealType: RealScalar> Max for NonNegativeRealScalar<RealType>
Implements Max for NonNegativeRealScalar.
impl<RealType: RealScalar> Max for NonNegativeRealScalar<RealType>
Implements Max for NonNegativeRealScalar.
Maximum selection is delegated to the default trait behavior based on PartialOrd.
Source§fn max_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self
fn max_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self
Source§fn max_by_value(self, other: Self) -> Self
fn max_by_value(self, other: Self) -> Self
Source§impl<RealType: RealScalar> Min for NonNegativeRealScalar<RealType>
Implements Min for NonNegativeRealScalar.
impl<RealType: RealScalar> Min for NonNegativeRealScalar<RealType>
Implements Min for NonNegativeRealScalar.
Minimum selection is delegated to the default trait behavior based on PartialOrd.
Source§fn min_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self
fn min_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self
Source§fn min_by_value(self, other: Self) -> Self
fn min_by_value(self, other: Self) -> Self
Source§impl<RealType: RealScalar> Mul for NonNegativeRealScalar<RealType>
Implements multiplicative composition for NonNegativeRealScalar.
impl<RealType: RealScalar> Mul for NonNegativeRealScalar<RealType>
Implements multiplicative composition for NonNegativeRealScalar.
Since both operands are guaranteed to be non-negative, their product is also non-negative.
Source§impl<'a, RealType: RealScalar> Mul<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements reference-based multiplication for NonNegativeRealScalar.
impl<'a, RealType: RealScalar> Mul<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements reference-based multiplication for NonNegativeRealScalar.
This allows multiplying a non-negative scalar by a reference to another non-negative scalar without consuming it. Since both operands are guaranteed to be non-negative, their product is also non-negative.
Source§type Output = NonNegativeRealScalar<RealType>
type Output = NonNegativeRealScalar<RealType>
* operator.Source§fn mul(
self,
other: &'a NonNegativeRealScalar<RealType>,
) -> NonNegativeRealScalar<RealType>
fn mul( self, other: &'a NonNegativeRealScalar<RealType>, ) -> NonNegativeRealScalar<RealType>
* operation. Read moreSource§impl<RealType: RealScalar> MulAssign for NonNegativeRealScalar<RealType>
Implements in-place multiplication for NonNegativeRealScalar by value.
impl<RealType: RealScalar> MulAssign for NonNegativeRealScalar<RealType>
Implements in-place multiplication for NonNegativeRealScalar by value.
This allows multiplying self by a non-negative scalar value.
Source§fn mul_assign(&mut self, other: NonNegativeRealScalar<RealType>)
fn mul_assign(&mut self, other: NonNegativeRealScalar<RealType>)
*= operation. Read moreSource§impl<'a, RealType: RealScalar> MulAssign<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements in-place reference-based multiplication for NonNegativeRealScalar.
impl<'a, RealType: RealScalar> MulAssign<&'a NonNegativeRealScalar<RealType>> for NonNegativeRealScalar<RealType>
Implements in-place reference-based multiplication for NonNegativeRealScalar.
This allows multiplying self by a reference to another non-negative scalar without consuming self.
Source§fn mul_assign(&mut self, other: &'a NonNegativeRealScalar<RealType>)
fn mul_assign(&mut self, other: &'a NonNegativeRealScalar<RealType>)
*= operation. Read moreSource§impl<RealType: RealScalar> NeumaierAddable for NonNegativeRealScalar<RealType>
Implements Neumaier compensated summation for NonNegativeRealScalar.
impl<RealType: RealScalar> NeumaierAddable for NonNegativeRealScalar<RealType>
Implements Neumaier compensated summation for NonNegativeRealScalar.
This implementation delegates to the underlying real scalar type’s Neumaier compensated sum operation, preserving numerical stability for sums of non-negative values.
Source§fn neumaier_compensated_sum(
value: Self,
sum: &mut Self,
compensation: &mut Self,
)
fn neumaier_compensated_sum( value: Self, sum: &mut Self, compensation: &mut Self, )
Source§impl<RealType: RealScalar> One for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> One for NonNegativeRealScalar<RealType>
Source§impl<RealType: PartialEq + RealScalar> PartialEq for NonNegativeRealScalar<RealType>
impl<RealType: PartialEq + RealScalar> PartialEq for NonNegativeRealScalar<RealType>
Source§impl<RealType: PartialOrd + RealScalar> PartialOrd for NonNegativeRealScalar<RealType>
impl<RealType: PartialOrd + RealScalar> PartialOrd for NonNegativeRealScalar<RealType>
Source§impl<RealType: RealScalar> Pow<i8> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<i8> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i8>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i8>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<i16> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<i16> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i16>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i16>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<i32> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<i32> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i32>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i32>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<i64> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<i64> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i64>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i64>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<i128> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<i128> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i128>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, i128>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<isize> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<isize> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, isize>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, isize>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<u8> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<u8> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u8>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u8>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<u16> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<u16> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u16>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u16>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<u32> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<u32> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u32>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u32>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<u64> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<u64> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u64>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u64>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<u128> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<u128> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u128>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, u128>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> Pow<usize> for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> Pow<usize> for NonNegativeRealScalar<RealType>
Source§type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, usize>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
type Error = FunctionErrors<PowIntExponentInputErrors<<RealType as IntoInner>::InnerType, usize>, <<RealType as IntoInner>::InnerType as RawScalarValidate>::ValidationError>
try_pow method.
This type must implement std::error::Error for proper error handling.Source§impl<RealType: RealScalar> ScalarCore for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> ScalarCore for NonNegativeRealScalar<RealType>
Source§type RawScalarType = <RealType as ScalarCore>::RawScalarType
type RawScalarType = <RealType as ScalarCore>::RawScalarType
Source§fn as_raw_scalar_ref(&self) -> &Self::RawScalarType
fn as_raw_scalar_ref(&self) -> &Self::RawScalarType
Source§fn into_raw_scalar(self) -> Self::RawScalarType
fn into_raw_scalar(self) -> Self::RawScalarType
Source§impl<RealType> Serialize for NonNegativeRealScalar<RealType>where
RealType: Serialize + RealScalar,
impl<RealType> Serialize for NonNegativeRealScalar<RealType>where
RealType: Serialize + RealScalar,
impl<RealType: PartialEq + RealScalar> StructuralPartialEq for NonNegativeRealScalar<RealType>
Source§impl<RealType: RealScalar> TryNew for NonNegativeRealScalar<RealType>
impl<RealType: RealScalar> TryNew for NonNegativeRealScalar<RealType>
Source§fn try_new(value: RealType) -> Result<Self, Self::Error>
fn try_new(value: RealType) -> Result<Self, Self::Error>
Attempts to create a NonNegativeRealScalar from a value.
§Errors
Returns ErrorsNonNegativeRealScalar::NegativeValue if the input is negative.
§Panics (Debug Mode Only)
In debug builds, panics if the input is not finite (NaN or infinity).
§Examples
use num_valid::scalars::{NonNegativeRealScalar, ErrorsNonNegativeRealScalar};
use try_create::TryNew;
// Zero is valid
assert!(NonNegativeRealScalar::try_new(0.0_f64).is_ok());
// Positive is valid
assert!(NonNegativeRealScalar::try_new(1.0_f64).is_ok());
// Negative is rejected
assert!(matches!(
NonNegativeRealScalar::try_new(-1.0_f64),
Err(ErrorsNonNegativeRealScalar::NegativeValue { .. })
));Source§type Error = ErrorsNonNegativeRealScalar<RealType>
type Error = ErrorsNonNegativeRealScalar<RealType>
try_new method.Source§impl<RealType: RealScalar> Zero for NonNegativeRealScalar<RealType>
Implements Zero for NonNegativeRealScalar.
impl<RealType: RealScalar> Zero for NonNegativeRealScalar<RealType>
Implements Zero for NonNegativeRealScalar.
The zero value is always valid, and acts as the additive identity.
Auto Trait Implementations§
impl<RealType> Freeze for NonNegativeRealScalar<RealType>where
RealType: Freeze,
impl<RealType> RefUnwindSafe for NonNegativeRealScalar<RealType>where
RealType: RefUnwindSafe,
impl<RealType> Send for NonNegativeRealScalar<RealType>
impl<RealType> Sync for NonNegativeRealScalar<RealType>
impl<RealType> Unpin for NonNegativeRealScalar<RealType>where
RealType: Unpin,
impl<RealType> UnsafeUnpin for NonNegativeRealScalar<RealType>where
RealType: UnsafeUnpin,
impl<RealType> UnwindSafe for NonNegativeRealScalar<RealType>where
RealType: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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