Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > numbers rounding in Wheat and chessboard problem?

numbers rounding in Wheat and chessboard problem?
Thread Tools
ipsych
Fresh-Faced Recruit
Join Date: Jun 2006
Status: Offline
Reply With Quote
May 29, 2008, 05:29 AM
 
Hello,

I tried to calculate the numbers of grains of wheat on the 64th square of a chessboard in Numbers by writing 1 in cell B2, then =B2*2 in the cell below and then pulled it down until I reached the 64th cell. Since Numbers begins to use E+11, E+12 ... I checked the "1,0" box which displayed the values without scientific notation. However, when I compare the values displayed in cell 64 of 9.223.372.036.854.780.000(,00) with the value that it should be 9.223.372.036.854.775.808(,00) it seems that numbers rounds the last five digits.

Did I made a mistake and more importantly, how can I get Numbers to display the real value?

Thanks in advance,

Daniel
     
miawj
Fresh-Faced Recruit
Join Date: Mar 2005
Status: Offline
Reply With Quote
May 29, 2008, 08:06 AM
 
No, you have not made a mistake. And you can't get Numbers to display the real value. Although you probably know that fractions and irrational numbers lead to approximations you may wonder why binary computers can't double integers accurately.

There are 64 'bits' on a chessboard. Computers (typically) are accurate (with floating points) to 53 bits (not 64) because they need to use the other bits to store the sign and the position of the floating point. Although you know you are only using integers spreadsheets use floating points and will be accurate to only 52/53 bits (or 15/16 decimal significant figures.)

What Every Computer Scientist Should Know About Floating-Point Arithmetic - David Goldberg
Floating points - Wikipaedia

What worries me is that Excel ends up with a different approximation!
( Last edited by miawj; May 29, 2008 at 08:15 AM. Reason: pernickitiness)
     
ipsych  (op)
Fresh-Faced Recruit
Join Date: Jun 2006
Status: Offline
Reply With Quote
May 29, 2008, 08:24 AM
 
Hello miawj,

thank you very much for your answer ... that it can display only 15/16 decimal significant figures would explain why the first rounding 'error' occurs on the transition of square 50 (562.949.953.421.312 = 15 digits) to 51 (1.125.899.906.842.620 = 16 digits).

Hmmm ... there goes my confidence in the accuracy of computers ...

Thanks again and best regards

Daniel
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
May 29, 2008, 08:41 AM
 
What is described here is so called double-precision math. If you need more accuracy, you can use quad-precision, or in this case, simple integer math. One way to get this is to use the command-line app bc, which lets us you set the required precision manually. I don't recall if it ships with OS X, but you can certainly install it.

I wonder if apps like bash (the shell in Terminal) that lack floating point capabilities may not get the answer correct in this case, as they default to integer math. You could also use Applescript or write a C app to do integer math, I guess.
     
TETENAL
Addicted to MacNN
Join Date: Aug 2004
Location: FFM
Status: Offline
Reply With Quote
May 29, 2008, 10:11 AM
 
Of course computers can calculate in higher precision than what is supported by the hardware. Otherwise programs like Mathematica couldn't exist. Numbers doesn't seem to support this. Maybe it (and Calculator.app) should.

Arbitrary-precision arithmetic - Wikipedia, the free encyclopedia
     
mduell
Posting Junkie
Join Date: Oct 2005
Location: Houston, TX
Status: Offline
Reply With Quote
May 29, 2008, 01:08 PM
 
Using doubles instead of big ints... ugh, Apple.
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
May 31, 2008, 12:05 PM
 
Just like MS does for Excel. Just like apps like Wingz and Clarisworks did back in their day. Really, is there a spreadsheet that will use long longs in that situation?

BTW, bc is installed by default, and entering 2^63 will give you the right answer to the last digit.
     
TETENAL
Addicted to MacNN
Join Date: Aug 2004
Location: FFM
Status: Offline
Reply With Quote
May 31, 2008, 12:22 PM
 
Originally Posted by P View Post
BTW, bc is installed by default, and entering 2^63 will give you the right answer to the last digit.
Maybe, but it's the right answer to the wrong question. The right question would be 2⁶⁴-1.
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
Jun 1, 2008, 05:04 AM
 
Actually...

I tried to calculate the numbers of grains of wheat on the 64th square of a chessboard
Which is 2^63. 2^64-1 is the total number of grains on the entire chessboard (and bc gets that right as well).
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:03 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,