Question

I have two unsigned long long numbers l1 and l2. I cast those numbers to float and save them as f1 and f2.

f1 = (float) l1;
f2 = (float) l2;

Now consider l1 > l2 by some arbitrary amount, say 100.

Can there be a case such that f1 < f2 ?. (Here f1 is converted from l1 which is greater than l2). If yes, can you please demonstrate how to find such a number?

sizeof(float) = 4 and sizeof(unsigned long long) = 8.
Was it helpful?

Solution

Can there be a case such that f1 < f2

No: For any rounding mode, the conversion from integer to float is increasing. As long as you do not change the rounding mode between the conversion of l1 and that of l2, f1 and f2 are in the same order as l1 and l2 (they may be equal where l1 and l2 were different, though).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top