Why does fibonacci sequence script stop making sense at 92nd iteration?
So, Just for practice, I wrote a simple fibonacci sequence script in bash.
It works, but one thing I've noticed is that when ever it gets to the 92nd iteration, it starts throwing out weird numbers that don't make sense:
I've tested it in cygwin, on a solaris box at work, and on a rhel box at work, and all show the same thing when it hits 92.
I assume that it has something to do with the maximum value that can be saved in memory or something like that...but I'm not remotely a computer scientist, just a humble admin.
This is because of the numerican expression out of range.
Not to sound ungrateful...but that doesn't mean anything to me. I'm not doing this to achieve anything, just for practice. So I'm trying to understand why, when I do it in bash, I get the results that I do.
I'm not really looking for alternative languages this could be done in (though I welcome any critique on how I could have done my way better)...I just want to understand a bit more.
The answer to your question: you blew past the largest number that bash can handle.
bash uses integer datatypes for internal arithmetic operations. They only count up so far.
try:
On the system I ran the getconf command the largest positive integer my shell can deal with is: 2147483647
getconf is a good command for a sysadmin to know BTW.
So if its just for fun, write your own double precision, you know the rules 5+6 = 1 carry 1.
Just do the split at 9 decimal digits. Print the result with no spaces between the two values.
Not to sound ungrateful...but that doesn't mean anything to me. I'm not doing this to achieve anything, just for practice. So I'm trying to understand why, when I do it in bash, I get the results that I do.
It's odd that you'd get those results in bash. It's the one bourne shell I've found that can handle really, really, really huge integer values. (not float, integer!) At least in my version. What version do you have?
and yes, that's on a 32-bit system. I"ve seen bash 3.x (and maybe 2.x) handle enormous ints too. But I suppose the 93rd fibbonaci number might exceed even that. Simply put, you're running out of bits to represent numbers with, causing the number to wrap around past -MAX. With a signed 8-bit number, adding one to 127 gets you -128...
Last edited by Corona688; 04-26-2010 at 12:34 PM..
Hi all,
I am trying out Solaris 11.3
Realize the option of -p when using beadm that i can actually create another boot environment on another pool.
root@Unicorn6:~# beadm create -p mypool solaris-1
root@Unicorn6:~# beadm list -a
BE/Dataset/Snapshot Flags... (1 Reply)
Okay so I'm making a simple text based game that branches into different scenarios. By branching I mean branching off into whole different files with that part of the game in it. I got tired of working on scenario 1 so I'm working on scenario 2. As I get started and try to test it, I get an error... (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I am trying to convert a C language program over to Sparc Assembley and I am getting Undefined first referenced... (4 Replies)
I wonder how to stop further loop iterations when conditions gets false e.g.
This file.txt contains the following structure :
1
2
3
4
5
6
7
8
9
10
How to stop iteration when if statement gets false ?
for n in `cat file.txt`
do
if (( n<=5 )) (1 Reply)
i have two separate scripts that work nicely to curl and generate two files.. one html and one txt so a total of four.
When the script starts up i want it to:
call and run shellscripta
call and run shellscriptb
sleep for about 40 seconds
again run shellscripta
again run shellscriptb
check... (4 Replies)
I'm posting the output from two disks on my Solaris machine. The first part is the output from using the format command and then using the verify option on each disk. The last part is the output from my df -k command. I'm trying to match the partition to the filesystem/mount point. I'm assuming... (13 Replies)
Hi,
I have a sun sparc system. I don't have a sun keyboard, hence i connected a pc keyboard.
I would like to know the "STOP A" equivalent command to be used on pc keyboard.
Regards,
Raja (4 Replies)
Can someone point me at resources for system calls? Specifically, I am trying to make sense of what I am seeing in a truss command. Thanks! (3 Replies)