# CFLib.org – Common Function Library Project

## FibCalc(x, y, top)

##### Last updated June 26, 2002

Version: 1 | Requires: CF5 | Library: MathLib

Description:
This script Calculates the Fibonacci sequence (each integer is the sum of the two previous integers). Note that the function will also calculate the sequence for non-Fibonacci numbers.

Return Values:
Returns a comma-delimited list of numeric values.

Example:

``````<cfoutput>
#fibcalc(0,1,200)#<BR>
#fibcalc(1,1,200)#
</cfoutput>
``````

Parameters:

Name Description Required
x First number in the Fibonacci sequence. Yes
y Second number in the Fibonacci sequence. Yes
top Ceiling for the Fibonacci number. The sequence will terminate when this value is reached. Yes

Full UDF Source:

``````/**
* This script Calculates the Fibonacci sequence  (each integer is the sum of the two previous integers).
*
* @param x      First number in the Fibonacci sequence. (Required)
* @param y      Second number in the Fibonacci sequence. (Required)
* @param top      Ceiling for the Fibonacci number.  The sequence will terminate when this value is reached. (Required)
* @return Returns a comma-delimited list of numeric values.
* @author Phillip B. Holmes (pholmes@mediares.com)
* @version 1, June 26, 2002
*/
function FibCalc(x,y,top){
var sequence = arrayNew(1);
var total = x+y;
sequence = x;
sequence = y;
while (total LTE top) {
ArrayAppend(sequence, total);
x=y;
y=total;
total=(x+y);
}
return ArrayToList(sequence, ',');
}
``````

### Search CFLib.org Raymond Camden added
QueryDeleteRows
November 04, 2017 Leigh added
May 11, 2016 Raymond Camden added
stripHTML
May 10, 2016 Kevin Cotton added
date2ExcelDate
May 05, 2016 Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson