Skip to main content

number_value

Function number_value 

Source
fn number_value(x: f64) -> Value
Expand description

Write a number as a CBOR integer when its value is integral, and as a float only when it is not.

The format’s encoding rule (SPEC.md, Interoperability) requires an integral value to be written as a CBOR integer rather than a float, and is about the value rather than the type the document gives the key. "effectiveRate" is the one key here declared a float, and its commonest value is 1.0 — “no rate-based dropping” — so writing it as a float meant the two implementations emitted different major types for the same trace, in the case that occurs most. Both readers accept either form; the bytes still differed, which is exactly what the rule exists to stop.

A value with a fractional part, one past the range a float carries integers exactly, and NaN or an infinity (whose fract() is NaN) all stay floats.