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§
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
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
impl GpuFloat for f32
Source§fn round(self) -> f32
fn round(self) -> f32
Returns the nearest integer to a number. Round half-way cases away from
0.0
.
Source§fn signum(self) -> f32
fn signum(self) -> f32
Returns a number that represents the sign of self
.
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number isNAN
intrinsics
Source§fn copysign(self, sign: f32) -> f32
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
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
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
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
fn powi(self, n: i32) -> f32
Raises a number to an integer power.
Using this function is generally faster than using powf
intrinsics
Source§fn sqrt(self) -> f32
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 log(self, base: f32) -> f32
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 hypot(self, other: f32) -> f32
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 asin(self) -> f32
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
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
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
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)
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
fn exp_m1(self) -> f32
Returns e^(self) - 1
in a way that is accurate even if the
number is close to zero.
Source§impl GpuFloat for f64
impl GpuFloat for f64
Source§fn round(self) -> f64
fn round(self) -> f64
Returns the nearest integer to a number. Round half-way cases away from
0.0
.
Source§fn signum(self) -> f64
fn signum(self) -> f64
Returns a number that represents the sign of self
.
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number isNAN
intrinsics
Source§fn copysign(self, sign: f64) -> f64
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
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
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
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
fn powi(self, n: i32) -> f64
Raises a number to an integer power.
Using this function is generally faster than using powf
intrinsics
Source§fn sqrt(self) -> f64
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 log(self, base: f64) -> f64
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 hypot(self, other: f64) -> f64
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 asin(self) -> f64
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
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
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
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)
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
fn exp_m1(self) -> f64
Returns e^(self) - 1
in a way that is accurate even if the
number is close to zero.