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§
const PI: Self
const PI: Self
Archimedes’ constant (π)
Required Methods§
fn acos(self) -> Self
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].
fn asin(self) -> Self
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].
fn atan(self) -> Self
fn atan(self) -> Self
Computes the arctangent of a number.
Return value is in radians in the range [-pi/2, pi/2];
fn atan2(y: Self, x: Self) -> Self
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)
fn ceil(self) -> Self
fn ceil(self) -> Self
Returns the smallest integer greater than or equal to a number.
fn cos(self) -> Self
fn cos(self) -> Self
Computes the cosine of a number (in radians).
fn div_euclid(self, other: Self) -> Self
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.
fn exp(self) -> Self
fn exp(self) -> Self
Returns e^(self)
, (the exponential function).
fn floor(self) -> Self
fn floor(self) -> Self
Returns the largest integer less than or equal to self
.
fn fract(self) -> Self
fn fract(self) -> Self
Returns the fractional part of self
.
fn ln(self) -> Self
fn ln(self) -> Self
Returns the natural logarithm of the number.
fn log(self, base: Self) -> Self
fn log(self, base: Self) -> Self
Returns the logarithm of the number with respect to an arbitrary base.
fn log10(self) -> Self
fn log10(self) -> Self
Returns the base 10 logarithm of the number.
fn log2(self) -> Self
fn log2(self) -> Self
Returns the base 2 logarithm of the number.
fn powf(self, n: Self) -> Self
fn powf(self, n: Self) -> Self
Raises a number to a floating point power.
fn recip(self) -> Self
fn recip(self) -> Self
Takes the reciprocal (inverse) of a number, 1/x
fn rem_euclid(self, other: Self) -> Self
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.
fn round(self) -> Self
fn round(self) -> Self
Returns the nearest integer to self
.
Round half-way cases away from 0.0
.
fn sin(self) -> Self
fn sin(self) -> Self
Computes the sine of a number (in radians).
fn sin_cos(self) -> (Self, Self)
fn sin_cos(self) -> (Self, Self)
Simultaneously computes the sine and cosine of the number, x
.
Returns (sin(x), cos(x))
.
fn sqrt(self) -> Self
fn sqrt(self) -> Self
Returns the square root of a number.
Returns NaN if self
is a negative number other than -0.0
.
fn tan(self) -> Self
fn tan(self) -> Self
Computes the tangent of a number (in radians).