Struct rust_examples::rsqrt::PositiveFloat  [−][src]
pub struct PositiveFloat(_);Expand description
Thin wrapper around f32 with additional semantics that the values can only be positive floats and excluding infinity and nan.
Zero-cost abstraction
use std::mem::size_of;
use rust_examples::rsqrt::PositiveFloat;
assert_eq!(size_of::<PositiveFloat>(), size_of::<f32>());Automatic derivation or arithmetic operators
Notice that some of impls on PositiveFloat are automatically derived using
derive_more.
Implementations
Constructs new PositiveFloat from given f32 only if:
- it is sign positive
 - is a normal float value (i.e. not a zero, nan or infinity)
 
Note that this factory ensures the safety of PositiveFloat::fast_rsqrt as it makes the illegal states mentioned above unrepresentable.
Example
use rust_examples::rsqrt::PositiveFloat;
assert_eq!(PositiveFloat::new(-4.2), None);
assert_eq!(PositiveFloat::new(0.0), None);
assert_eq!(PositiveFloat::new(f32::NAN), None);
assert_eq!(PositiveFloat::new(f32::INFINITY), None);Approximates the inverse square root of given number.
This implementation is safe in the sense that by the construction of PositiveFloat, it is not possible to call PositiveFloat::fast_rsqrt on any invalid value: negative floats, zero, nan or infinity.
Constant generic parameter ITERS determines the number of iterations of the Newton’s
method used to find the approximation. Note that despite the fact that it is usize, the
implementation executes at least one iteration even if it is set to 0.
Trait Implementations
type Output = PositiveFloat
type Output = PositiveFloat
The resulting type after applying the + operator.
Performs the + operation. Read more
type Output = PositiveFloat
type Output = PositiveFloat
The resulting type after applying the * operator.
Performs the * operation. Read more
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
Auto Trait Implementations
impl RefUnwindSafe for PositiveFloat
impl Send for PositiveFloat
impl Sync for PositiveFloat
impl Unpin for PositiveFloat
impl UnwindSafe for PositiveFloat
Blanket Implementations
Mutably borrows from an owned value. Read more
