Trait GpuFloat

Source
pub trait GpuFloat:
    Copy
    + PartialOrd
    + Sealed {
Show 38 methods // Required methods fn floor(self) -> Self; fn ceil(self) -> Self; fn round(self) -> Self; fn trunc(self) -> Self; fn fract(self) -> Self; fn abs(self) -> Self; fn signum(self) -> Self; fn copysign(self, sign: Self) -> Self; fn mul_add(self, a: Self, b: Self) -> Self; fn div_euclid(self, rhs: Self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn powi(self, n: i32) -> Self; fn powf(self, n: Self) -> Self; fn sqrt(self) -> Self; fn exp(self) -> Self; fn exp2(self) -> Self; fn ln(self) -> Self; fn log(self, base: Self) -> Self; fn log2(self) -> Self; fn log10(self) -> Self; fn cbrt(self) -> Self; fn hypot(self, other: Self) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn tan(self) -> Self; fn asin(self) -> Self; fn acos(self) -> Self; fn atan(self) -> Self; fn atan2(self, other: Self) -> Self; fn sin_cos(self) -> (Self, Self); fn exp_m1(self) -> Self; fn ln_1p(self) -> Self; fn sinh(self) -> Self; fn cosh(self) -> Self; fn tanh(self) -> Self; fn asinh(self) -> Self; fn acosh(self) -> Self; fn atanh(self) -> Self;
}
Expand description

std float intrinsics implemented using libdevice intrinsics so they can be used from GPU no_std crates. Falls back to stdlib implementation on non-nvptx.

Required Methods§

Source

fn floor(self) -> Self

Source

fn ceil(self) -> Self

Source

fn round(self) -> Self

Source

fn trunc(self) -> Self

Source

fn fract(self) -> Self

Source

fn abs(self) -> Self

Source

fn signum(self) -> Self

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

fn sqrt(self) -> Self

Source

fn exp(self) -> Self

Source

fn exp2(self) -> Self

Source

fn ln(self) -> Self

Source

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

Source

fn log2(self) -> Self

Source

fn log10(self) -> Self

Source

fn cbrt(self) -> Self

Source

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

Source

fn sin(self) -> Self

Source

fn cos(self) -> Self

Source

fn tan(self) -> Self

Source

fn asin(self) -> Self

Source

fn acos(self) -> Self

Source

fn atan(self) -> Self

Source

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

Source

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

Source

fn exp_m1(self) -> Self

Source

fn ln_1p(self) -> Self

Source

fn sinh(self) -> Self

Source

fn cosh(self) -> Self

Source

fn tanh(self) -> Self

Source

fn asinh(self) -> Self

Source

fn acosh(self) -> Self

Source

fn atanh(self) -> Self

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 GpuFloat for f32

Source§

fn floor(self) -> f32

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

Source§

fn ceil(self) -> f32

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

Source§

fn round(self) -> f32

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

Source§

fn trunc(self) -> f32

Returns the integer part of a number.

Source§

fn fract(self) -> f32

Returns the fractional part of a number.

Source§

fn abs(self) -> f32

Computes the absolute value of self. Returns NAN if the number is NAN.

Source§

fn signum(self) -> f32

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 NANintrinsics
Source§

fn copysign(self, sign: f32) -> f32

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

Equal to self if the sign of self and sign are the same, otherwise equal to -self. If self is a NAN, then a NAN with the sign of sign is returned.

Source§

fn mul_add(self, a: f32, b: f32) -> f32

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add.

Using mul_add may be more performant than an unfused multiply-add if the target architecture has a dedicated fma CPU instruction. However, this is not always true, and will be heavily dependant on designing algorithms with specific target hardware in mind.

Source§

fn div_euclid(self, rhs: f32) -> f32

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 rem_euclid(self, rhs: f32) -> f32

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) approximatively.

Source§

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

Raises a number to an integer power.

Using this function is generally faster than using powfintrinsics

Source§

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

Raises a number to a floating point power.

Source§

fn sqrt(self) -> f32

Returns the square root of a number.

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

Source§

fn exp(self) -> f32

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

Source§

fn exp2(self) -> f32

Returns 2^(self).

Source§

fn ln(self) -> f32

Returns the natural logarithm of the number.

Source§

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

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

The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.

Source§

fn log2(self) -> f32

Returns the base 2 logarithm of the number.

Source§

fn log10(self) -> f32

Returns the base 10 logarithm of the number.

Source§

fn cbrt(self) -> f32

Returns the cube root of a number.

Source§

fn hypot(self, other: f32) -> f32

Calculates the length of the hypotenuse of a right-angle triangle given legs of length x and y.

Source§

fn sin(self) -> f32

Computes the sine of a number (in radians).

Source§

fn cos(self) -> f32

Computes the cosine of a number (in radians).

Source§

fn tan(self) -> f32

Computes the tangent of a number (in radians).

Source§

fn asin(self) -> f32

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 acos(self) -> f32

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 atan(self) -> f32

Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2];intrinsics

Source§

fn atan2(self, other: f32) -> f32

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)intrinsics
Source§

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

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

Source§

fn exp_m1(self) -> f32

Returns e^(self) - 1 in a way that is accurate even if the number is close to zero.

Source§

fn ln_1p(self) -> f32

Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately.

Source§

fn sinh(self) -> f32

Hyperbolic sine function.

Source§

fn cosh(self) -> f32

Hyperbolic cosine function.

Source§

fn tanh(self) -> f32

Hyperbolic tangent function.

Source§

fn asinh(self) -> f32

Inverse hyperbolic sine function.

Source§

fn acosh(self) -> f32

Inverse hyperbolic cosine function.

Source§

fn atanh(self) -> f32

Inverse hyperbolic tangent function.

Source§

impl GpuFloat for f64

Source§

fn floor(self) -> f64

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

Source§

fn ceil(self) -> f64

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

Source§

fn round(self) -> f64

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

Source§

fn trunc(self) -> f64

Returns the integer part of a number.

Source§

fn fract(self) -> f64

Returns the fractional part of a number.

Source§

fn abs(self) -> f64

Computes the absolute value of self. Returns NAN if the number is NAN.

Source§

fn signum(self) -> f64

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 NANintrinsics
Source§

fn copysign(self, sign: f64) -> f64

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

Equal to self if the sign of self and sign are the same, otherwise equal to -self. If self is a NAN, then a NAN with the sign of sign is returned.

Source§

fn mul_add(self, a: f64, b: f64) -> f64

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add.

Using mul_add may be more performant than an unfused multiply-add if the target architecture has a dedicated fma CPU instruction. However, this is not always true, and will be heavily dependant on designing algorithms with specific target hardware in mind.

Source§

fn div_euclid(self, rhs: f64) -> f64

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 rem_euclid(self, rhs: f64) -> f64

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) approximatively.

Source§

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

Raises a number to an integer power.

Using this function is generally faster than using powfintrinsics

Source§

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

Raises a number to a floating point power.

Source§

fn sqrt(self) -> f64

Returns the square root of a number.

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

Source§

fn exp(self) -> f64

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

Source§

fn exp2(self) -> f64

Returns 2^(self).

Source§

fn ln(self) -> f64

Returns the natural logarithm of the number.

Source§

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

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

The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.

Source§

fn log2(self) -> f64

Returns the base 2 logarithm of the number.

Source§

fn log10(self) -> f64

Returns the base 10 logarithm of the number.

Source§

fn cbrt(self) -> f64

Returns the cube root of a number.

Source§

fn hypot(self, other: f64) -> f64

Calculates the length of the hypotenuse of a right-angle triangle given legs of length x and y.

Source§

fn sin(self) -> f64

Computes the sine of a number (in radians).

Source§

fn cos(self) -> f64

Computes the cosine of a number (in radians).

Source§

fn tan(self) -> f64

Computes the tangent of a number (in radians).

Source§

fn asin(self) -> f64

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 acos(self) -> f64

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 atan(self) -> f64

Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2];intrinsics

Source§

fn atan2(self, other: f64) -> f64

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)intrinsics
Source§

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

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

Source§

fn exp_m1(self) -> f64

Returns e^(self) - 1 in a way that is accurate even if the number is close to zero.

Source§

fn ln_1p(self) -> f64

Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately.

Source§

fn sinh(self) -> f64

Hyperbolic sine function.

Source§

fn cosh(self) -> f64

Hyperbolic cosine function.

Source§

fn tanh(self) -> f64

Hyperbolic tangent function.

Source§

fn asinh(self) -> f64

Inverse hyperbolic sine function.

Source§

fn acosh(self) -> f64

Inverse hyperbolic cosine function.

Source§

fn atanh(self) -> f64

Inverse hyperbolic tangent function.

Implementors§