3 ms·
My first computer back in 1978 used North Star BASIC which used Binary Coded Decimal (BCD) in which 0.1 + 0.2 really did equal 0.3. When I struck binary floats
by simonblack 6y ago
My first computer back in 1978 used North Star BASIC which used Binary Coded Decimal (BCD) in which 0.1 + 0.2 really did equal 0.3.
When I struck binary floats a year or two later in Livermore Labs BASIC, I thought they were stupid, not at all like the good stuff that I was using.
- JPLeRouzic 6y agoThanks for the anecdote. I am not sure if it is sensible to convert all floating point numbers before doing the operation. I understand (but may be wrong) that if we follow Wikipedia [0] and represent them with the same exponent: 0.1 + 0.2 = (1 * 10^⁻1) + (2 * 10^-1) then (1 + 2) * 10^⁻1 = 3 * 10^-1 It is not symbolic reasoning, it is just that calculations on the fraction and exponent are done separately. Addition of the two fraction parts are addition of integers. 0001 + 0010 gives 0011 (3) in binary. It does not matter that 3 * 10^-1 = 0.29999999999999998889776975 The comparison result gives TRUE, not FALSE There are indeed limitations, but for the example given it works. I think that a long time ago (in the 70') I was taught that having the same exponent was mandatory for floating point arithmetic, or maybe I read it in a Byte/drDobbs article. [0] https://en.wikipedia.org/wiki/Floating-point_arithmetic#Addition_and_subtraction https://en.wikipedia.org/wiki/Floating-point_arithmetic#Addi...
- deleted 6y ago[deleted]