Calculator use: when adding isn’t associative(?)

Tutoring math, curiosities can arise. The tutor mentions a calculator one.

In front of me are two reliable scientific calculators from different manufacturers. Both give the following results:

2+1exp20-1exp20 = 0

but

2+(1exp20-1exp20)=2

1exp20 means scientific notation: 1×1020.

How can the two statements above lead to different answers?

Theoretically both equal 2, but the first one gives 0 for a practical reason. 1exp20 means 1 with 20 zeros behind it, or 100 000 000 000 000 000 000. 2 is so tiny in comparison that
2 + 1exp20 ≈ 1exp20. From that premise,
2+1exp20-1exp20=1exp20-1exp20=0.

With 2+(1exp20-1exp20), however, 1exp20-1exp20 is evaluated first, to exactly 0. 2+0 results, giving 2.

Source:

Bryant, Randal E. and David R. O’Hallaron. Computer Systems: A Programmer’s Perspective, 3rd ed. Boston: Pearson, 2016.

dev.w3.org

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply