3
votes

I'm not sure how to go about this problem.

I know that the smallest integer not representable by IEEE 754 would be 2^(mantissa+1) + 1 but how would I take that info and change it to an even number?

I've thought about maxing out the mantissa bits and then scaling by a factor of 2 but would that be correct?

1
I think you might have meant 2**number_of_mantissa_bits+1? For even numbers, you gain one binade, so 2**(number-of-mantissa-bits+1)+2.njuffa
@njuffa so then that is the smallest even number then? it makes complete sense to me, but for some reason our cs course has 2^(mantissa + 2) + 2, any idea why? or is that a typo?ylun.ca
Well, how are you counting number_of_mantissa_bits? Do you count the bits in the IEEE-754 encoding only, or do you count the effective number of mantissa bits, that is, the coded (fractional) bits plus the implicit (hidden) integer bit?njuffa
Only the number of mantissa bits, which is why its confusing me @njuffaylun.ca
@ylun.ca If you are only counting the number of mantissa bits encoded in an IEEE-754 format with an implicit integer bit, the smallest integer that cannot be presented exactly is 2**(number_of_mantissa_bits+1)+1. The smallest even integer that cannot be represented exactly is 2**(number_of_mantissa_bits+2)+2, as your course materials state. You can easily clarify this for yourself by looking at the smallest spacing between encoded numbers in each binade. Or you could check brute force using IEEE-754 single precision operands.njuffa

1 Answers

0
votes

Just adding 2 to 2 ** (num_mantissa_bits) is insufficient because the final bit in the mantissa will exactly represent the two that you added.

Instead, compute 2 ** (num_mantissa_bits + 1) + 2

Here's a Python session that makes all the bits visible:

>>> (2.0 ** 53).hex()
'0x1.0000000000000p+53'
>>> (2.0 ** 53 + 2.0).hex()
'0x1.0000000000001p+53'
>>> (2.0 ** 54).hex()
'0x1.0000000000000p+54'
>>> (2.0 ** 54 + 2.0).hex()
'0x1.0000000000000p+54'