0

I want to know how to subtract IEEE 754 numbers so I searched about this and found this answer: How to subtract IEEE 754 numbers?, and it works fine with all the examples I've tried, except when I substract one, the number 1 have a lot of 0's in the mantissa, so by this logic a number should stay the same when I substract 1 to it?

PS: It would be the same for any number - 2^something, the mantissa would be full of 0's.

Someone explain pls

Community
  • 1
  • 1
Patricio Sard
  • 2,092
  • 3
  • 22
  • 52

1 Answers1

1

When an IEEE 754 number is stored, it uses a very memory-efficient method.

All numbers except for very very small ones (so-called de-normalized numbers) can be written in the form:

sign * 1.mmmmmmmmmmmmmmmmm * 2^eeeee

When they are stored, only the seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm bits are actually stored.

When storing 1.0000000, the mmmmmmm bits are all zero, and the leading 1. is not stored, since that would be redundant. Therefore the mantissa in the stored bits is all-zeros. The mathematical value of the mantissa though is:

mantissa = 1 + 0.mmmmmmm

Actually, the exponent is also stored a little differently, to allow for both positive and negative exponents. But that’s outside the scope of this question.

For more information, see the Wikipedia article on this subject.

Roland Illig
  • 40,703
  • 10
  • 88
  • 121