Float

Trait Float 

Source
pub trait Float: Num {
    const PI: Self;
Show 26 methods // Required methods fn acos(self) -> Self; fn asin(self) -> Self; fn atan(self) -> Self; fn atan2(y: Self, x: Self) -> Self; fn ceil(self) -> Self; fn cos(self) -> Self; fn div_euclid(self, other: Self) -> Self; fn exp(self) -> Self; fn floor(self) -> Self; fn fract(self) -> Self; fn is_finite(self) -> bool; fn ln(self) -> Self; fn log(self, base: Self) -> Self; fn log10(self) -> Self; fn log2(self) -> Self; fn powf(self, n: Self) -> Self; fn powi(self, n: i32) -> Self; fn recip(self) -> Self; fn rem_euclid(self, other: Self) -> Self; fn round(self) -> Self; fn sin(self) -> Self; fn sin_cos(self) -> (Self, Self); fn sqrt(self) -> Self; fn tan(self) -> Self; fn from_f32(x: f32) -> Self; fn as_f32(self) -> f32;
}
Expand description

Floating point number, including NaN/Inf

Required Associated Constants§

Source

const PI: Self

Archimedes’ constant (π)

Required Methods§

Source

fn acos(self) -> Self

Computes the arccosine of a number.

Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1].

Source

fn asin(self) -> Self

Computes the arcsine of a number.

Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1].

Source

fn atan(self) -> Self

Computes the arctangent of a number.

Return value is in radians in the range [-pi/2, pi/2];

Source

fn atan2(y: Self, x: Self) -> Self

Computes the four quadrant arctangent of self (y) and other (x) in radians.

  • 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

fn ceil(self) -> Self

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

Source

fn cos(self) -> Self

Computes the cosine of a number (in radians).

Source

fn div_euclid(self, other: Self) -> Self

Calculates Euclidean division, the matching method for rem_euclid.

This computes the integer n such that self = n * rhs + self.rem_euclid(rhs). In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs.

Source

fn exp(self) -> Self

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

Source

fn floor(self) -> Self

Returns the largest integer less than or equal to self.

Source

fn fract(self) -> Self

Returns the fractional part of self.

Source

fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

Source

fn ln(self) -> Self

Returns the natural logarithm of the number.

Source

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

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

Source

fn log10(self) -> Self

Returns the base 10 logarithm of the number.

Source

fn log2(self) -> Self

Returns the base 2 logarithm of the number.

Source

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

Raises a number to a floating point power.

Source

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

Raises a number to an integer power.

Source

fn recip(self) -> Self

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

Source

fn rem_euclid(self, other: Self) -> Self

Calculates the least nonnegative remainder of self (mod rhs).

In particular, the return value r satisfies 0.0 <= r < rhs.abs() in most cases. However, due to a floating point round-off error it can result in r == rhs.abs(), violating the mathematical definition, if self is much smaller than rhs.abs() in magnitude and self < 0.0. This result is not an element of the function’s codomain, but it is the closest floating point number in the real numbers and thus fulfills the property self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs) approximately.

Source

fn round(self) -> Self

Returns the nearest integer to self. Round half-way cases away from 0.0.

Source

fn sin(self) -> Self

Computes the sine of a number (in radians).

Source

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

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

Source

fn sqrt(self) -> Self

Returns the square root of a number.

Returns NaN if self is a negative number other than -0.0.

Source

fn tan(self) -> Self

Computes the tangent of a number (in radians).

Source

fn from_f32(x: f32) -> Self

Convert an f32 into Self

Source

fn as_f32(self) -> f32

Convert self into an f32

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Float for f32

Source§

const PI: Self = 3.14159274f32

Source§

fn acos(self) -> Self

Source§

fn asin(self) -> Self

Source§

fn atan(self) -> Self

Source§

fn atan2(y: Self, x: Self) -> Self

Source§

fn ceil(self) -> Self

Source§

fn cos(self) -> Self

Source§

fn div_euclid(self, other: Self) -> Self

Source§

fn exp(self) -> Self

Source§

fn floor(self) -> Self

Source§

fn fract(self) -> Self

Source§

fn is_finite(self) -> bool

Source§

fn ln(self) -> Self

Source§

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

Source§

fn log10(self) -> Self

Source§

fn log2(self) -> Self

Source§

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

Source§

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

Source§

fn recip(self) -> Self

Source§

fn rem_euclid(self, other: Self) -> Self

Source§

fn round(self) -> Self

Source§

fn sin(self) -> Self

Source§

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

Source§

fn sqrt(self) -> Self

Source§

fn tan(self) -> Self

Source§

fn from_f32(x: f32) -> Self

Source§

fn as_f32(self) -> f32

Source§

impl Float for f64

Source§

const PI: Self = 3.1415926535897931f64

Source§

fn acos(self) -> Self

Source§

fn asin(self) -> Self

Source§

fn atan(self) -> Self

Source§

fn atan2(y: Self, x: Self) -> Self

Source§

fn ceil(self) -> Self

Source§

fn cos(self) -> Self

Source§

fn div_euclid(self, other: Self) -> Self

Source§

fn exp(self) -> Self

Source§

fn floor(self) -> Self

Source§

fn fract(self) -> Self

Source§

fn is_finite(self) -> bool

Source§

fn ln(self) -> Self

Source§

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

Source§

fn log10(self) -> Self

Source§

fn log2(self) -> Self

Source§

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

Source§

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

Source§

fn recip(self) -> Self

Source§

fn rem_euclid(self, other: Self) -> Self

Source§

fn round(self) -> Self

Source§

fn sin(self) -> Self

Source§

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

Source§

fn sqrt(self) -> Self

Source§

fn tan(self) -> Self

Source§

fn from_f32(x: f32) -> Self

Source§

fn as_f32(self) -> f32

Implementors§

Source§

impl<T: Real> Float for T

Source§

const PI: Self = <Self as Real>::PI