ncmetric

Function ncmetric 

Source
pub fn ncmetric(
    val: c_ulong,
    s: usize,
    decimal: c_ulong,
    buf: &str,
    omitdec: i32,
    mult: c_ulong,
    uprefix: i32,
) -> NcResult<&str>
Expand description

Takes an arbitrarily large number, and prints it into a fixed-size buffer by adding the necessary SI suffix.

Usually, pass a |NC[IB]PREFIXSTRLEN+1|-sized buffer to generate up to |NC[IB]PREFIXCOLUMNS| columns’ worth of EGCs. The characteristic can occupy up through |mult-1| characters (3 for 1000, 4 for 1024). The mantissa can occupy either zero or two characters.

snprintf(3) is used internally, with s as its size bound. If the output requires more size than is available, an error will be returned.

Floating-point is never used, because an IEEE758 double can only losslessly represent integers through 2^53-1.

2^64-1 is 18446744073709551615, 18.45E(xa). KMGTPEZY thus suffice to handle an 89-bit uintmax_t. Beyond Z(etta) and Y(otta) lie lands unspecified by SI. 2^-63 is 0.000000000000000000108, 1.08a(tto).

val: value to print s: maximum output size. decimal: scaling. ‘1’ if none has taken place. buf: buffer in which string will be generated omitdec: inhibit printing of all-0 decimal portions mult: base of suffix system (almost always 1000 or 1024) uprefix: character to print following suffix (‘i’ for kibibytes basically). only printed if suffix is actually printed (input >= mult).

You are encouraged to consult notcurses_metric(3).