ComplexNumAdd(First, Second)
Last updated November 15, 2001
Version: 1 | Requires: ColdFusion 5 | Library: MathLib
Description:
Add two complex numbers that have been stored as a structure using the ComplexNum() UDF. You can also use this function to add a complex and a real number, or even two real numbers. The result is stored in a structure.
Return Values:
Returns a structure.
Example:
<cfset b = ComplexNum(1,-10)>
<cfset c = ComplexNumAdd(a,b)>
<cfset d = ComplexNumAdd(a,3)>
<cfoutput>
#ComplexNumToString(a)# + #ComplexNumToString(b)# = #ComplexNumToString(c)#<br>
#ComplexNumToString(a)# + 3 = #ComplexNumToString(d)#
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| First | Structure containing a complex number or a real number. | Yes |
| Second | Structure containing a complex number or a real number. | Yes |
Full UDF Source:
<cfscript>
/**
* Adds two complex numbers.
* Note that this function uses complex numbers stored as structures by the ComplexNum() UDF also available in this library. The ComplexNum() function is also required for this UDF to function.
*
* @param First Structure containing a complex number or a real number.
* @param Second Structure containing a complex number or a real number.
* @return Returns a structure.
* @author Matthew Walker (matthew@electricsheep.co.nz)
* @version 1, November 15, 2001
*/
function ComplexNumAdd(First,Second) {
var ComplexSum = StructNew();
var ComplexFirst = 0;
var ComplexSecond = 0;
var R = 0;
var I = 0;
if ( IsStruct(First) )
ComplexFirst = First;
else
ComplexFirst = ComplexNum(First,0);
if ( IsStruct(Second) )
ComplexSecond = Second;
else
ComplexSecond = ComplexNum(Second,0);
R = ComplexFirst.R + ComplexSecond.R;
I = ComplexFirst.I + ComplexSecond.I;
StructInsert(ComplexSum, "R", R);
StructInsert(ComplexSum, "I", I);
return ComplexSum;
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)