std::intrinsics::float (v0.2.2)
Floating-point intrinsics: abs, min, max, sqrt, fused multiply-add.
Latest
Overview
std::intrinsics::float exposes low-level floating-point operations through intrinsic bindings: absolute value, minimum, maximum, square root, and fused multiply-add.
Use these when you need precise control over floating-point behavior.
Source: thrustc/std/v0.2.2/intrinsics/float.thrust
Public Signatures
Exported declarations for this module snapshot.
fn absolute [T] (value: T) T @public;
fn copySign [T] (magnitude: T, sign: T) T @public;
fn minimum [T] (left: T, right: T) T @public;
fn maximum [T] (left: T, right: T) T @public;
fn squareRoot [T] (value: T) T @public;
fn fusedMultiplyAdd [T] (left: T, right: T, addend: T) T @public;
fn floor [T] (value: T) T @public;
fn ceiling [T] (value: T) T @public;
fn truncate [T] (value: T) T @public;
fn round [T] (value: T) T @public;
Behavior and Use
These intrinsics wrap LLVM floating-point operations such as abs, min, max, sqrt, and fma.
Use them when the normal operators do not expose the exact operation or rounding you need.
Examples
import std::intrinsics::float;
import std::io;
// Compute the diagonal of a square with side 3.
fn main() s32 @public {
var diagonal: f64 = float::squareRoot[f64](18.0);
io::print("diagonal: %d\n", (diagonal as s32));
return 0;
}
import std::intrinsics::float;
import std::io;
// Round a measurement down to whole units.
fn main() s32 @public {
var whole: f64 = float::floor[f64](2.7);
io::print("whole units: %d\n", (whole as s32));
return 0;
}
import std::intrinsics::float;
import std::io;
// Evaluate a*x + b as a single fused operation.
fn main() s32 @public {
var y: f64 = float::fusedMultiplyAdd[f64](2.0, 3.0, 1.0);
io::print("y: %d\n", (y as s32));
return 0;
}
Notes
- These map closely to LLVM floating-point intrinsics.
- Wrap them in helpers when used across many call sites.