Skip to main content

push_human

Function push_human 

Source
pub fn push_human(out: &mut Vec<u8>, d: f64)
Expand description

Appends a double the way INCRBYFLOAT and HINCRBYFLOAT write one, which is not the way everything else does.

Those two go through ld2string in its human mode rather than through d2string, and the human mode is %.17Lf with the trailing zeros taken off and a lone -0 turned back into 0. Being a fixed point conversion it never writes an exponent, so INCRBYFLOAT key 1e30 answers a one and thirty zeros where ZSCORE would answer 1e+30 for the same number.

The digits are the shortest ones rather than seventeen decimal places of the f64, and that is the closer answer rather than the lazier one. Redis holds the value in a long double, so %.17Lf of one tenth is 0.10000000000000000 and comes back as 0.1 once the zeros are stripped. Seventeen decimal places of the f64 would be 0.10000000000000001, which is a worse match for the same reason D-11 gives: the extra width is what makes the long double print cleanly, and shortest digits land on the same text without pretending to have it.