Hi when reinterpreting a 32-bit string of bits one could end up having a valid floating point number:

uint: 1101004800, float: 20.000000

Now say i'm working with a static-analysis tool that defines operations on ranges of values instead of single values.

One such operation i am considering is reinterpreting the 32-bit bitstring value of an unsigned value into a float.

Is a range of two unsigned integers [uint(a1) uint(a2)] when converted to float [float(a1) float(a2)] , still a continuous range?

I know that float has special values for NaN, infinity. But otherwise would this range-conversion hold?

The following numbers would suggest it is the case:

int: 1101004800, float:  20.000000
int: 1101004801, float:  20.000002
int: 1101004802, float:  20.000004
int: 1101004803, float:  20.000006
int: 1101004804, float:  20.000008
int: 1101004805, float:  20.000010
int: 1101004806, float:  20.000011
int: 1101004807, float:  20.000013
int: 1101004808, float:  20.000015
int: 1101004809, float:  20.000017

I've read here that "the bit sequence, allows floating-point numbers to be compared and sorted correctly even when interpreting them as integers."

1

There are 1 best solutions below

0
On

It can work up to fmax representation but not further (float have sign magnitude kind of representation, so order will be reversed for negative).

0000 0000 -> 0.0
...
7F7F FFFF -> fmax
7F80 0000 -> +Inf
7F80 0001 - 7FFF FFFF -> NaN
8000 0000 -> -0.0
...
FF7F FFFF -> -fmax
FF80 0000 -> -Inf
FF80 0001 - FFFF FFFF -> NaN

But what is the intention? What operation are you going to perform on those ranges that could not be performed on integers?