My undergraduate computer science professor warned me there would be days like this. I paid no heed to his advice because he probably sounded like this paper reads.
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Why does it matter? Because they have invented something that was supposed to make my life easier and interoperable with platforms called object serialization to xml, it offered auto-magic conversions. But no, not for floating point!
Unless you wish to hear a sordid story of keyboard groping, fumbling for the truth, you should stop now.
But now I have a grudge against STORING floating point numbers. It all started with one question – Why is the exponent value in floating point number data structure, for raising 2 to a power, and NOT 10?
https://en.wikipedia.org/wiki/IEEE_754
For some reason, I thought floating point numbers were stored in scientific notation.
value = mantissa * (10exponent)
so
123.75 = 1.2375 * 100 = 1.2375 * 102I used 123.75, instead of the more natural 123.45
But floating point is not scientific notation. It just has a similar idea. (funny thing, I kept the exponent term in base10, b/c 2 in binary is what?… 10… Wouldn’t that be confusing?)
(binary) (binary) (base10) 1111011.11 = 1.11101111 * 26
Why they do this, I can only imagine it makes things easier for designers somehow.
But there is a conversion problem for fractions between base 10 and base 2 number systems. Some fractions with a denominator that is power of 10 (which is what our decimal system is), cannot be converted into a fraction whose denominator is a power of 2, and vice versa. This is the source of the problem. When I need it in a “human” readable format, the base 2 fraction, is converted to base 10 fraction, and back again, when stored in the computer.
Once I realized that floating point wasn’t scientific notation, I stupidly asked myself why doesn’t the computer do “decimal calculations” in base10 scientific notation, so my conversion problem goes away? After all, scientific notation “1.2345678 x 103” translates to text of decimal representation real easy “1234.5678”.
So as you may have guessed, I never saw what a floating point circuit looked like in college, so I don’t know why exponents in powers of 2 makes it easier. Nevertheless, how would using the exponent as power of two, make it easier to do:
Addition
base2mantissa1 x 2exponent1 + base2mantissa2 x 2exponent2
or
Multiplication
base2mantissa1 x 2exponent1 x base2mantissa2 x 2exponent2
Multiplication in base10 is so easy in scientific notation, so I can’t imagine why anyone would use base2 exponents.
base10mantissa1 x 10exponent1 x base10mantissa2 x 10exponent2 ---------------------- (base10mantissa1 * base10mantissa2) * (10(exponent1 + exponent2)) ---------------------- Which if you really think about it, is the same as: (base2mantissa1 * base2mantissa2) * (2(exponent1 + exponent2))
Because adding and multiplying integers gets the same result in base2 or base 10. And that is what it is really doing with the mantissa and exponents. You can say the mantissa is fractional, but you can easily make it an integer by moving multiples of ten to the exponent.
Damn, I think I just answered my own question. Floating Point Addition might be harder if the exponents were stored in base10. The difference between the exponents tell us what the offset between 2 numbers, before adding.
This is base2 addition: 1.01000010101001 x 22 +1.111101111 x 24 ------------------------ 101.000010101001 x 20 +11111.01111 x 20 ------------------------
It’s easier just to move the decimal point in base2 exponents, and decrement the exponent and keep the mantissa digits the same. If you want to move the decimal point in base10, you are multiplying by 10, not by 2. Multiplying by 2, just shifts binary representation. Multiplying by 10, changes the digits in binary.
base10, changing the exponent, probably has to change the mantissa. Here is what happens to binary representation of 2, 2×10, 2×100.
Decimal (base 10) | Binary (base 2) |
---|---|
2 | 10 |
20 | 10100 |
200 | 11001000 |
I guess I can transmit floating point numbers like
base2mantissa x 2exponent, so there is no conversion. Maybe I should transmit in hexadecimal. But then it’s not human readable anymore. Nor will the other side understand 0x1a56.e71.