pub trait GpuFloat: Copy + PartialOrd + Sealed {
Show 38 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

Implementations on Foreign Types

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

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

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

Returns the integer part of a number.

Returns the fractional part of a number.

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

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

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.

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.

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.

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.

Raises a number to an integer power.

Using this function is generally faster than using powfintrinsics

Raises a number to a floating point power.

Returns the square root of a number.

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

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

Returns 2^(self).

Returns the natural logarithm of the number.

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.

Returns the base 2 logarithm of the number.

Returns the base 10 logarithm of the number.

Returns the cube root of a number.

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

Computes the sine of a number (in radians).

Computes the cosine of a number (in radians).

Computes the tangent of a number (in radians).

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

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

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

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

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

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

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

Hyperbolic sine function.

Hyperbolic cosine function.

Hyperbolic tangent function.

Inverse hyperbolic sine function.

Inverse hyperbolic cosine function.

Inverse hyperbolic tangent function.

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

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

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

Returns the integer part of a number.

Returns the fractional part of a number.

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

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

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.

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.

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.

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.

Raises a number to an integer power.

Using this function is generally faster than using powfintrinsics

Raises a number to a floating point power.

Returns the square root of a number.

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

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

Returns 2^(self).

Returns the natural logarithm of the number.

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.

Returns the base 2 logarithm of the number.

Returns the base 10 logarithm of the number.

Returns the cube root of a number.

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

Computes the sine of a number (in radians).

Computes the cosine of a number (in radians).

Computes the tangent of a number (in radians).

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

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

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

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

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

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

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

Hyperbolic sine function.

Hyperbolic cosine function.

Hyperbolic tangent function.

Inverse hyperbolic sine function.

Inverse hyperbolic cosine function.

Inverse hyperbolic tangent function.

Implementors