Bob John
Bob John

Reputation: 3878

Adding floating point numbers, why is this the result?

Suppose we wanted to add the IEEE 754 floating point numbers:

1.00101 • 22 and -1.00111 • 23

We first adjust the first number to match exponents: 1.00101 • 22 = 0.100101 • 23

The we add together to obtain -101.001, which we can convert to a floating point approximation.

Can someone explain how we add together to obtain the result -101.001, I'm having a hard time understanding how this number was obtained and would really appreciate some help here.

Upvotes: 0

Views: 83

Answers (1)

Bernhard Barker
Bernhard Barker

Reputation: 55589

Switch the signs just to make it easier (we'll switch it back in the end), following this logic:

a + -b = c --> -(a + -b) = -c --> -a + b = -c

Then add them: (which is really subtraction)

  1.001110
- 0.100101
----------
  0.101001

Then you have -0.101001 • 23 = -101.001.

Upvotes: 2

Related Questions