Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Why does fibonacci sequence script stop making sense at 92nd iteration? Post 302416115 by DeCoTwc on Sunday 25th of April 2010 03:08:57 AM
Old 04-25-2010
Why does fibonacci sequence script stop making sense at 92nd iteration?

So, Just for practice, I wrote a simple fibonacci sequence script in bash.

Code:
(03:08:02\[D@DeCoBox15)
[~]$ cat fib
#!/usr/bin/bash				

ret ()
{
        echo -ne "\n"
        sleep .5
}


a=1
b=2
echo -n $a      #1      A
ret
echo -n $b      #2      B
ret

while true
do
        c=$(($a+$b))
        echo -n $c      #3      C
        ret
        a=$(($c+$b))
        echo -ne $a     #5      A
        ret
        b=$(($c+$a))
        echo -ne $b     #8      B
        ret
done

(03:05:20\[D@DeCoBox15)
[~]$ ./fib|head -15|nl
     1  1
     2  2
     3  3
     4  5
     5  8
     6  13
     7  21
     8  34
     9  55
    10  89
    11  144
    12  233
    13  377
    14  610
    15  987

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:

Code:
(03:05:05\[D@DeCoBox15)
[~]$ ./fib|head -92|nl|tail -1
    92  -6246583658587674878

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.

So can anyone explain this a bit for me?
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Process calls - making sense of truss results

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)
Discussion started by: jpeery
3 Replies

2. Solaris

STOP A sequence

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)
Discussion started by: RajaRC
4 Replies

3. Solaris

Making sense of df -k & format verify output

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)
Discussion started by: gonzotonka
13 Replies

4. UNIX for Dummies Questions & Answers

Need help making a start/stop script...

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)
Discussion started by: phpfreak
4 Replies

5. Shell Programming and Scripting

Shell script to find the sum of first n Fibonacci numbers

pls give me the solution for this i need it for my exam pls pls pls Shell script to find the sum of first n Fibonacci numbers (1 Reply)
Discussion started by: Kshitija
1 Replies

6. Shell Programming and Scripting

howto stop loop iteration

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)
Discussion started by: presul
1 Replies

7. Homework & Coursework Questions

program to find and print a Fibonacci sequence of numbers. --Errors

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)
Discussion started by: kenjiro310
4 Replies

8. Programming

This Makes NO sense. I'm making a game and getting an error, need help.

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)
Discussion started by: lemonoid
1 Replies

9. Solaris

Beadm create -p on another pool - making sense of it

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)
Discussion started by: javanoob
1 Replies
PAPI_set_granularity(3) 					       PAPI						   PAPI_set_granularity(3)

NAME
PAPI_set_granularity - Set the default counting granularity for eventsets bound to the cpu component. SYNOPSIS
Detailed Description @par C Prototype: int PAPI_set_granularity( int granularity ); @param -- granularity one of the following constants as defined in the papi.h header file @arg PAPI_GRN_THR -- Count each individual thread @arg PAPI_GRN_PROC -- Count each individual process @arg PAPI_GRN_PROCG -- Count each individual process group @arg PAPI_GRN_SYS -- Count the current CPU @arg PAPI_GRN_SYS_CPU -- Count all CPUs individually @arg PAPI_GRN_MIN -- The finest available granularity @arg PAPI_GRN_MAX -- The coarsest available granularity Return values: PAPI_OK PAPI_EINVAL One or more of the arguments is invalid. PAPI_set_granularity sets the default counting granularity for all new event sets created by PAPI_create_eventset. This call implicitly sets the granularity for the cpu component (component 0) and is included to preserve backward compatibility. Example: int ret; // Initialize the library ret = PAPI_library_init(PAPI_VER_CURRENT); if (ret > 0 && ret != PAPI_VER_CURRENT) { fprintf(stderr,"PAPI library version mismatch!0); exit(1); } if (ret < 0) handle_error(ret); // Set the default granularity for the cpu component ret = PAPI_set_granularity(PAPI_GRN_PROC); if (ret != PAPI_OK) handle_error(ret); ret = PAPI_create_eventset(&EventSet); if (ret != PAPI_OK) handle_error(ret); * See Also: PAPI_set_cmp_granularity PAPI_set_domain PAPI_set_opt PAPI_get_opt Author Generated automatically by Doxygen for PAPI from the source code. Version 5.2.0.0 Tue Jun 17 2014 PAPI_set_granularity(3)
All times are GMT -4. The time now is 02:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy