Skip to main content

Real

Trait Real 

Source
pub trait Real: Num + Copy {
    const PI: Self;
Show 25 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 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

Real number (differs from Float as doesn’t support NaN)

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 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".

Implementors§

Source§

impl<T: Float> Real for RealImpl<T>

Source§

const PI: Self