Struct micromath::F32

source ·
pub struct F32(pub f32);
Expand description

32-bit floating point wrapper which implements fast approximation-based operations.

Tuple Fields§

§0: f32

Implementations§

source§

impl F32

source

pub fn abs(self) -> Self

Computes the absolute value of self.

Returns Self::NAN if the number is Self::NAN.

source§

impl F32

source

pub fn asin(self) -> Self

Computes asin(x) approximation in radians in the range [-pi/2, pi/2].

source§

impl F32

source

pub fn atan(self) -> Self

Approximates atan(x) approximation in radians with a maximum error of 0.002.

Returns Self::NAN if the number is Self::NAN.

source

pub fn atan_norm(self) -> Self

Approximates atan(x) normalized to the [−1,1] range with a maximum error of 0.1620 degrees.

source§

impl F32

source

pub fn atan2(self, rhs: Self) -> Self

Approximates the four quadrant arctangent of self (y) and rhs (x) in radians with a maximum error of 0.002.

  • x = 0, y = 0: 0
  • x >= 0: arctan(y/x) -> [-pi/2, pi/2]
  • y >= 0: arctan(y/x) + pi -> (pi/2, pi]
  • y < 0: arctan(y/x) - pi -> (-pi, -pi/2)
source§

impl F32

source

pub fn ceil(self) -> Self

Returns the smallest integer greater than or equal to a number.

source§

impl F32

source

pub fn copysign(self, sign: Self) -> Self

Returns a number composed of the magnitude of self and the sign of sign.

source§

impl F32

source

pub fn cos(self) -> Self

Approximates cos(x) in radians with a maximum error of 0.002.

source§

impl F32

source

pub fn div_euclid(self, rhs: Self) -> Self

Calculates Euclidean division, the matching method for rem_euclid.

source§

impl F32

source

pub fn exp(self) -> Self

Returns e^(self), (the exponential function).

source§

impl F32

source

pub fn floor(self) -> Self

Returns the largest integer less than or equal to a number.

source§

impl F32

source

pub fn fract(self) -> Self

Returns the fractional part of a number with sign.

source§

impl F32

source

pub fn hypot(self, rhs: Self) -> Self

Calculate the length of the hypotenuse of a right-angle triangle.

source§

impl F32

source

pub fn inv(self) -> Self

Fast approximation of 1/x.

source§

impl F32

source

pub fn invsqrt(self) -> Self

Approximate inverse square root with an average deviation of ~5%.

source§

impl F32

source

pub fn ln(self) -> Self

Approximates the natural logarithm of the number.

source§

impl F32

source

pub fn log(self, base: Self) -> Self

Approximates the logarithm of the number with respect to an arbitrary base.

source§

impl F32

source

pub fn log10(self) -> Self

Approximates the base 10 logarithm of the number.

source§

impl F32

source

pub fn log2(self) -> Self

Approximates the base 2 logarithm of the number.

source§

impl F32

source

pub fn mul_add(self, a: Self, b: Self) -> Self

Computes (self * a) + b.

source§

impl F32

source

pub fn powf(self, n: Self) -> Self

Approximates a number raised to a floating point power.

source§

impl F32

source

pub fn powi(self, n: i32) -> Self

Approximates a number raised to an integer power.

source§

impl F32

source

pub fn recip(self) -> Self

Returns the reciprocal (inverse) of a number, 1/x.

source§

impl F32

source

pub fn rem_euclid(self, rhs: Self) -> Self

Calculates the least non-negative remainder of self (mod rhs).

source§

impl F32

source

pub fn round(self) -> Self

Returns the nearest integer to a number.

source§

impl F32

source

pub fn signum(self) -> Self

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN
source§

impl F32

source

pub fn sin(self) -> Self

Approximates sin(x) in radians with a maximum error of 0.002.

source§

impl F32

source

pub fn sin_cos(self) -> (Self, Self)

Simultaneously computes the sine and cosine of the number, x. Returns (sin(x), cos(x)).

source§

impl F32

source

pub fn sqrt(self) -> Self

Approximates the square root of a number with an average deviation of ~5%.

Returns Self::NAN if self is a negative number.

source§

impl F32

source

pub fn tan(self) -> Self

Approximates tan(x) in radians with a maximum error of 0.6.

source§

impl F32

source

pub fn trunc(self) -> Self

Returns the integer part of a number.

source§

impl F32

source

pub const ZERO: Self = _

The value 0.0.

source

pub const ONE: Self = _

The value 1.0.

source

pub const RADIX: u32 = 2u32

The radix or base of the internal representation of f32.

source

pub const MANTISSA_DIGITS: u32 = 24u32

Number of significant digits in base 2.

source

pub const DIGITS: u32 = 6u32

Approximate number of significant digits in base 10.

source

pub const EPSILON: Self = _

Machine epsilon value for f32.

This is the difference between 1.0 and the next larger representable number.

source

pub const MIN: Self = _

Smallest finite f32 value.

source

pub const MIN_POSITIVE: Self = _

Smallest positive normal f32 value.

source

pub const MAX: Self = _

Largest finite f32 value.

source

pub const MIN_EXP: i32 = -125i32

One greater than the minimum possible normal power of 2 exponent.

source

pub const MAX_EXP: i32 = 128i32

Maximum possible power of 2 exponent.

source

pub const MIN_10_EXP: i32 = -37i32

Minimum possible normal power of 10 exponent.

source

pub const MAX_10_EXP: i32 = 38i32

Maximum possible power of 10 exponent.

source

pub const NAN: Self = _

Not a Number (NaN).

source

pub const INFINITY: Self = _

Infinity (∞).

source

pub const NEG_INFINITY: Self = _

Negative infinity (−∞).

source

pub fn is_nan(self) -> bool

Returns true if this value is NaN.

source

pub fn is_infinite(self) -> bool

Returns true if this value is positive infinity or negative infinity, and false otherwise.

source

pub fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

source

pub fn is_sign_positive(self) -> bool

Returns true if self has a positive sign, including +0.0, NaNs with positive sign bit and positive infinity.

source

pub fn is_sign_negative(self) -> bool

Returns true if self has a negative sign, including -0.0, NaNs with negative sign bit and negative infinity.

source

pub fn to_bits(self) -> u32

Raw transmutation to u32.

This is currently identical to transmute::<f32, u32>(self) on all platforms.

See F32::from_bits for some discussion of the portability of this operation (there are almost no issues).

source

pub fn from_bits(v: u32) -> Self

Raw transmutation from u32.

This is currently identical to transmute::<u32, f32>(v) on all platforms. It turns out this is incredibly portable, for two reasons:

  • Floats and Ints have the same endianness on all supported platforms.
  • IEEE-754 very precisely specifies the bit layout of floats.

See f32::from_bits for more information.

Trait Implementations§

source§

impl Add<F32> for f32

§

type Output = F32

The resulting type after applying the + operator.
source§

fn add(self, rhs: F32) -> F32

Performs the + operation. Read more
source§

impl Add<f32> for F32

§

type Output = F32

The resulting type after applying the + operator.
source§

fn add(self, rhs: f32) -> F32

Performs the + operation. Read more
source§

impl Add for F32

§

type Output = F32

The resulting type after applying the + operator.
source§

fn add(self, rhs: F32) -> F32

Performs the + operation. Read more
source§

impl AddAssign<F32> for f32

source§

fn add_assign(&mut self, rhs: F32)

Performs the += operation. Read more
source§

impl AddAssign<f32> for F32

source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
source§

impl AddAssign for F32

source§

fn add_assign(&mut self, rhs: F32)

Performs the += operation. Read more
source§

impl Clone for F32

source§

fn clone(&self) -> F32

Returns a copy 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 F32

source§

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

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

impl Default for F32

source§

fn default() -> F32

Returns the “default value” for a type. Read more
source§

impl Display for F32

source§

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

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

impl Div<F32> for f32

§

type Output = F32

The resulting type after applying the / operator.
source§

fn div(self, rhs: F32) -> F32

Performs the / operation. Read more
source§

impl Div<f32> for F32

§

type Output = F32

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> F32

Performs the / operation. Read more
source§

impl Div for F32

§

type Output = F32

The resulting type after applying the / operator.
source§

fn div(self, rhs: F32) -> F32

Performs the / operation. Read more
source§

impl DivAssign<F32> for f32

source§

fn div_assign(&mut self, rhs: F32)

Performs the /= operation. Read more
source§

impl DivAssign<f32> for F32

source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
source§

impl DivAssign for F32

source§

fn div_assign(&mut self, rhs: F32)

Performs the /= operation. Read more
source§

impl From<F32> for f32

source§

fn from(n: F32) -> f32

Converts to this type from the input type.
source§

impl From<f32> for F32

source§

fn from(n: f32) -> F32

Converts to this type from the input type.
source§

impl From<i16> for F32

source§

fn from(n: i16) -> F32

Converts to this type from the input type.
source§

impl From<i8> for F32

source§

fn from(n: i8) -> F32

Converts to this type from the input type.
source§

impl From<u16> for F32

source§

fn from(n: u16) -> F32

Converts to this type from the input type.
source§

impl From<u8> for F32

source§

fn from(n: u8) -> F32

Converts to this type from the input type.
source§

impl FromStr for F32

§

type Err = ParseFloatError

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

fn from_str(src: &str) -> Result<F32, ParseFloatError>

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

impl Inv for F32

Available on crate feature num-traits only.
§

type Output = F32

The result after applying the operator.
source§

fn inv(self) -> Self

Returns the multiplicative inverse of self. Read more
source§

impl LowerExp for F32

source§

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

Formats the value using the given formatter.
source§

impl Mul<F32> for f32

§

type Output = F32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: F32) -> F32

Performs the * operation. Read more
source§

impl Mul<f32> for F32

§

type Output = F32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> F32

Performs the * operation. Read more
source§

impl Mul for F32

§

type Output = F32

The resulting type after applying the * operator.
source§

fn mul(self, rhs: F32) -> F32

Performs the * operation. Read more
source§

impl MulAssign<F32> for f32

source§

fn mul_assign(&mut self, rhs: F32)

Performs the *= operation. Read more
source§

impl MulAssign<f32> for F32

source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
source§

impl MulAssign for F32

source§

fn mul_assign(&mut self, rhs: F32)

Performs the *= operation. Read more
source§

impl Neg for F32

§

type Output = F32

The resulting type after applying the - operator.
source§

fn neg(self) -> F32

Performs the unary - operation. Read more
source§

impl Num for F32

Available on crate feature num-traits only.
§

type FromStrRadixErr = ParseFloatError

source§

fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
source§

impl One for F32

Available on crate feature num-traits only.
source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

impl PartialEq<F32> for f32

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<f32> for F32

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for F32

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<F32> for f32

source§

fn partial_cmp(&self, other: &F32) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<f32> for F32

source§

fn partial_cmp(&self, other: &f32) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd for F32

source§

fn partial_cmp(&self, other: &F32) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Product for F32

source§

fn product<I>(iter: I) -> Selfwhere I: Iterator<Item = F32>,

Method which takes an iterator and generates Self from the elements by multiplying the items.
source§

impl Rem<F32> for f32

§

type Output = F32

The resulting type after applying the % operator.
source§

fn rem(self, rhs: F32) -> F32

Performs the % operation. Read more
source§

impl Rem<f32> for F32

§

type Output = F32

The resulting type after applying the % operator.
source§

fn rem(self, rhs: f32) -> F32

Performs the % operation. Read more
source§

impl Rem for F32

§

type Output = F32

The resulting type after applying the % operator.
source§

fn rem(self, rhs: F32) -> F32

Performs the % operation. Read more
source§

impl RemAssign<f32> for F32

source§

fn rem_assign(&mut self, rhs: f32)

Performs the %= operation. Read more
source§

impl RemAssign for F32

source§

fn rem_assign(&mut self, rhs: F32)

Performs the %= operation. Read more
source§

impl Sub<F32> for f32

§

type Output = F32

The resulting type after applying the - operator.
source§

fn sub(self, rhs: F32) -> F32

Performs the - operation. Read more
source§

impl Sub<f32> for F32

§

type Output = F32

The resulting type after applying the - operator.
source§

fn sub(self, rhs: f32) -> F32

Performs the - operation. Read more
source§

impl Sub for F32

§

type Output = F32

The resulting type after applying the - operator.
source§

fn sub(self, rhs: F32) -> F32

Performs the - operation. Read more
source§

impl SubAssign<F32> for f32

source§

fn sub_assign(&mut self, rhs: F32)

Performs the -= operation. Read more
source§

impl SubAssign<f32> for F32

source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
source§

impl SubAssign for F32

source§

fn sub_assign(&mut self, rhs: F32)

Performs the -= operation. Read more
source§

impl Sum for F32

source§

fn sum<I>(iter: I) -> Selfwhere I: Iterator<Item = F32>,

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl UpperExp for F32

source§

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

Formats the value using the given formatter.
source§

impl Zero for F32

Available on crate feature num-traits only.
source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl Component for F32

Available on crate feature vector only.
source§

impl Copy for F32

source§

impl StructuralPartialEq for F32

Auto Trait Implementations§

§

impl RefUnwindSafe for F32

§

impl Send for F32

§

impl Sync for F32

§

impl Unpin for F32

§

impl UnwindSafe for F32

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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> NumAssign for Twhere T: Num + NumAssignOps,

source§

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

source§

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