Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fibonacci example broken for high numbers - indicative of deep problems with language function? #1947

Closed
gopherbot opened this issue Jun 12, 2011 · 1 comment

Comments

@gopherbot
Copy link
Contributor

by robinwinslowmorris:

The Fibonacci example on the website doesn't work past 2 billion. I'm worried this might
be indicative of deeper problems.

What steps will reproduce the problem?
1. Go to http://golang.org.
2. Load up the Fobonacci example.
3. Edit the "main" function so that it execudes "fn()" 47 times (I
think).
4. Observe that the last 3 numbers output are "1134903170 1836311903
-1323752223". This is not Finonacci.
5. Similar weirdness continues for even higher numbers.

What is the expected output?
Well, 1134903170 + 1836311903 = 2971215073. So:
1134903170 1836311903 2971215073

What do you see instead?
1134903170 1836311903 -1323752223

Which compiler are you using (5g, 6g, 8g, gccgo)?
Whatever's on the website http://golang.org/.

Which operating system are you using?
Ditto.
I'm viewing the website using Google Chrome 12.0.742.91 on Windows 7.

Which revision are you using?  (hg identify)
Ditto

Other info:
I know nothing about "go". I was just thinking of learning it. This bug I
found straight away makes me slightly disinclined to bother.
@robpike
Copy link
Contributor

robpike commented Jun 12, 2011

Comment 1:

This is a toy program demonstrating in the context a familiar problem things more
interesting than integer arithmetic.
What you're seeing is integer overflow. Machines have fixed-size words.  It would be an
easy exercise to rewrite this code to use package big.

Status changed to Unfortunate.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants