FibGen(x, y, numSeq)
Last updated June 26, 2002
Version: 1 | Requires: CF5 | Library: MathLib
Description:
Returns the Fibonacci sequence to n places given a starting point of x and y (each integer is the sum of the two previous integers). Note that the function will also calculate the sequence for non-Fibonacci numbers. Based on FibCalc() by Phillip B. Holmes (pholmes@mediares.com).
Return Values:
Returns a comma-delimited list of numbers.
Example:
<cfoutput>
#FibGen(0,1,10)#<BR>
#FibGen(1,1,10)#
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
x | First number in the sequence. | Yes |
y | Second number in the sequence. | Yes |
numSeq | Number of elements to generate for the sequence. | Yes |
Full UDF Source:
/**
* Returns the Fibonacci sequence to n places given a starting point of x and y.
*
* @param x First number in the sequence. (Required)
* @param y Second number in the sequence. (Required)
* @param numSeq Number of elements to generate for the sequence. (Required)
* @return Returns a comma-delimited list of numbers.
* @author Rob Brooks-Bilson (rbils@amkor.com)
* @version 1, June 26, 2002
*/
function FibGen(x,y,numSeq){
var sequence = arrayNew(1);
var total = x+y;
var i=1;
sequence[1] = x;
sequence[2] = y;
while (i LTE numSeq-2) {
total=(x+y);
ArrayAppend(sequence, total);
x=y;
y=total;
i=i+1;
}
return ArrayToList(sequence, ',');
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016