I am writing a protocol, that uses RFC 7049 as its binary representation. The standard states, that the protocol may use 32-bit floating point representation of numbers, if their numeric value is equivalent to respective 64-bit numbers. The conversion must not lead to lose of precision.
- What 32-bit float numbers can be bigger than 64-bit integer and numerically equivalent with them?
- Is comparing
float x; uint64_t y; (float)x == (float)y
enough for ensuring, that the values are equivalent? Will this comparison ever be true?
For the purposes of this specification, all number representations for the same numeric value are equivalent. This means that an encoder can encode a floating-point value of 0.0 as the integer 0. It, however, also means that an application that expects to find integer values only might find floating-point values if the encoder decides these are desirable, such as when the floating-point value is more compact than a 64-bit integer.
What 32-bit float numbers can be bigger than 64-bit integer and numerically equivalent with them?
None: by definition, a numberX
that's equal toY
can't be greater thanY
. – Ichthyic1.0f == float(1ull)
– Ichthyic