dtrunc

Converts a floating point value to an integer.

This function relies on the D behavior when casting a floating point value to an integer. It uses SSE2 on X86_64 and the FPU on X86 but it can always be inlined.

int
dtrunc
@trusted pure nothrow
(
T
)
()

Parameters

value
Type: T

Either a float or a double.

Return Value

Type: int

An integral value equal to the value nearest integral toward 0.

Examples

assert(dtrunc(0.2f) == 0);
assert(dtrunc(0.8f) == 0);
assert(dtrunc(-0.2f) == 0);
assert(dtrunc(-8.8f) == -8);

Meta