quantize

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.

  1. Unqual!F quantize(F val, F unit)
  2. Unqual!F quantize(F val, E exp)
  3. Unqual!F quantize(F val)
    quantize
    (
    real base
    long exp = 1
    alias rfunc = rint
    F
    )
    (
    const F val
    )
    if (
    is(typeof(rfunc(F.init)) : F) &&
    )

Examples

import std.math.operations : isClose;

assert(isClose(12345.6789L.quantize!10(-2), 12345.68L));
assert(isClose(12345.6789L.quantize!(10, -2), 12345.68L));
assert(isClose(12345.6789L.quantize!(10, floor)(-2), 12345.67L));
assert(isClose(12345.6789L.quantize!(10, -2, floor), 12345.67L));

assert(isClose(12345.6789L.quantize!22(1), 12342.0L));
assert(isClose(12345.6789L.quantize!22, 12342.0L));

Meta