std.math.rounding

This is a submodule of std.math.

It contains several functions for rounding floating point numbers.

Members

Functions

ceil
real ceil(real x)
double ceil(double x)
float ceil(float x)

Returns the value of x rounded upward to the next integer (toward positive infinity).

floor
real floor(real x)
double floor(double x)
float floor(float x)

Returns the value of x rounded downward to the next integer (toward negative infinity).

lrint
long lrint(real x)

Rounds x to the nearest integer value, using the current rounding mode.

lround
long lround(real x)

Return the value of x rounded to the nearest integer.

nearbyint
real nearbyint(real x)

Rounds x to the nearest integer value, using the current rounding mode.

quantize
Unqual!F quantize(F val, F unit)

Round val to a multiple of unit. rfunc specifies the rounding function to use; by default this is rint, which uses the current rounding mode.

quantize
Unqual!F quantize(F val, E exp)
Unqual!F quantize(F val)

Round val to a multiple of pow(base, exp). rfunc specifies the rounding function to use; by default this is rint, which uses the current rounding mode.

rint
real rint(real x)
double rint(double x)
float rint(float x)

Rounds x to the nearest integer value, using the current rounding mode.

rndtol
long rndtol(real x)
long rndtol(double x)
long rndtol(float x)

Returns x rounded to a long value using the current rounding mode. If the integer value of x is greater than long.max, the result is indeterminate.

round
auto round(real x)

Return the value of x rounded to the nearest integer. If the fractional part of x is exactly 0.5, the return value is rounded away from zero.

trunc
real trunc(real x)

Returns the integer portion of x, dropping the fractional portion. This is also known as "chop" rounding. pure on all platforms.

Meta

Authors

Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger