Skip to main content

push_fixed4

Function push_fixed4 

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

Appends a distance the way the geo commands write one, which is four digits after the point and no exponent ever.

GEODIST and the WITHDIST half of a search go through Redis’s fixedpoint_d2string rather than through d2string, because “166.2742 km away” reads better than “166.27415156960033 km away” and four places is still a tenth of a metre when the unit is the kilometre. The trailing zeros stay, so a whole number of metres comes back as 5.0000 and a distance of nothing comes back as 0.0000.

The scaled value is rounded to the nearest, ties to even, which is what llrint does in the default rounding mode and therefore what a real server answers. Ties are not reachable in practice, since the value being rounded came out of a square root, but rounding the other way would still be a divergence that only showed up in somebody’s test suite.

A distance too large to scale into an integer writes nothing, which is what Redis does too: its formatter fails and hands the reply an empty string. Nothing reaches that from a real search, because the far side of the world is twenty thousand kilometres away and the scaled form of that is twelve digits.