D implementations of floor, ceil, and lrint functions are based on the CEPHES math library, which is Copyright (C) 2001 Stephen L. Moshier <steve@moshier.net≥ and are incorporated herein by permission of the author. The author reserves the right to distribute this material elsewhere under different copying permissions. These modifications are distributed here under the following terms:
std.math.rounding
This is a submodule of std.math.
It contains several functions for rounding floating point numbers.
Copyright
Copyright The D Language Foundation 2000 - 2011.
Functions 21
fn
real ceil(real x) @trusted pure nothrow @nogcReturns the value of x rounded upward to the next integer (toward positive infinity).fn
real floor(real x) @trusted pure nothrow @nogcReturns the value of x rounded downward to the next integer (toward negative infinity).fn
Unqual!F quantize(alias rfunc = rint, F)(const F val, const F unit) if (is(typeof(rfunc(F.init)) : F) && isFloatingPoint!F)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.fn
Unqual!F quantize(real base, alias rfunc = rint, F, E)(const F val, const E exp) if (is(typeof(rfunc(F.init)) : F) && isFloatingPoint!F && isIntegral!E)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.fn
Unqual!F quantize(real base, long exp = 1, alias rfunc = rint, F)(const F val) if (is(typeof(rfunc(F.init)) : F) && isFloatingPoint!F)dittofn
real nearbyint(real x) @safe pure nothrow @nogcRounds x to the nearest integer value, using the current rounding mode.fn
real rint(real x) @safe pure nothrow @nogcRounds x to the nearest integer value, using the current rounding mode.fn
long lrint(real x) @trusted pure nothrow @nogcRounds x to the nearest integer value, using the current rounding mode.fn
auto round(real x) @trusted nothrow @nogcReturn 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.fn
real trunc(real x) @trusted nothrow @nogc pureReturns the integer portion of x, dropping the fractional portion. This is also known as "chop" rounding. `pure` on all platforms.fn
long rndtol(real x) @nogc @safe pure nothrowReturns 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.