Summations not producing correct answers when inputting really big numbers?

Here is the link to my function: Graphing Calculator. Inputting 13^7 produces 2 but 13^8 produces 21594. This really doesn’t seem right, so how likely is it that its glitching somehow?

This is all thanks to the magic of floating point numbers!

Computers can only work with finitely many numbers, which means there will always be gaps between one computer number and the next. For various reasons, it was decided that numbers near zero should have very small gaps. As a consequence, as you move further away from zero, the gaps between numbers start to grow — eventually, the gap between computer numbers becomes even larger than the gap between integers!

You can see this in your graph by evaluating (13^8)^2, and comparing it to (13^8)^2+63: the calculator will believe these numbers are the same value, because the gap is so large around that value! Then, if you write ((13^8)^2+64) - (13^8)^2, you’ll see the calculator believes the result is 128.

Your ceil - floor expression is essentially adding up the gaps between integers, so when you start going high enough, you’re going to start accumulating floating point errors.

2 Likes