# CFLib.org – Common Function Library Project

##### Last updated July 18, 2001

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Returns a structure containing the two real roots of a polynomial in the form: ax^2 + bx + c = 0

Return Values:
Returns a structure.

Example:

``````<CFSET a = 1>
<CFSET b = -3>
<CFSET c = -4>

<CFOUTPUT>
Given a = 1, b = -3, c = -4
</CFOUTPUT>

<P>
<P>

Parameters:

Name Description Required
a Coefficient of x^2 term Yes
b Coefficient of x term Yes
c Constant Yes

Full UDF Source:

``````/**
* Returns the two real roots of a polynomial in the form: ax^2 + bx + c = 0
*
* @param a 	 Coefficient of x^2 term
* @param b 	 Coefficient of x term
* @param c 	 Constant
* @return Returns a structure.
* @author Joel Cox (jlcox@goodyear.com)
* @version 1, July 18, 2001
*/
{
Var mRoots = StructNew();
Var first = 0;
Var second = 0;
Var denom = 2 * a;
Var arg1 = b^2 - 4 * a * c;
if (arg1 LT 0) {
mRoots["Root1"] = "not real";
mRoots["Root2"] = "not real";
}
else {
first = -b / denom;
second = Sqr(arg1) / denom;
mRoots["Root1"] = first + second;
mRoots["Root2"] = first - second;
}
Return mRoots;
}``````

date2ExcelDate
May 5, 2016

CapFirst
April 25, 2016