# Complex Numbers Procedures

Procedures to work with complex numbers. Complex numbers are represented using the type `_complex`. The real and imaginary part are stored in the members `x` and `y`.

    TYPE _complex
       x AS DOUBLE   ' real part
       y AS DOUBLE   ' imaginary part
    END TYPE

Include file: AfxComplex.inc.

### Operators

Name | Description
--- | ---
Comparison operators | Compares complex numbers.
Math operators | Add, subtract, multiply or divide complex numbers.

### Methods and Properties

Name | Description
--- | ---
CAbs | Returns the magnitude of a complex number.
CAbs2 | Returns the squared magnitude of a complex number, otherwise known as the complex norm.
CAbsSqr | Returns the absolute square (squared norm) of a complex number.
CACos | Returns the complex arccosine of a complex number.
CACosH | Returns the complex hyperbolic arccosine of a complex number. The branch cut is on the real axis, less than 1.
CACosHReal | Returns the complex arccosine of a complex number.
CACosReal | Returns the complex arccosine of a real number.
CACot | Returns the complex arccotangent of a complex number.
CACotH | Returns the complex hyperbolic arccotangent of a complex number.
CACsc | Returns the complex arccosecant of a complex number.
CACscH | Returns the complex hyperbolic arccosecant of a complex number.
CACscReal | Returns the complex arccosecant of a real number.
CAddImag | Adds an imaginary number.
CAddReal | Adds a real number.
CArcCos | Returns the complex arccosine of a complex number.
CArcCosH | Returns the complex hyperbolic arccosine of a complex number.
CArcCosHReal | Returns the complex arccosine of a complex number.
CArcCosReal | Returns the complex arccosine of a real number.
CArcCot | Returns the complex arccotangent of a complex number.
CArcCotH | Returns the complex hyperbolic arccotangent of a complex number.
CArcCsc | Returns the complex arccosecant of a complex number.
CArcCscH | Returns the complex hyperbolic arccosecant of a complex number.
CArcCscReal | Returns the complex arccosecant of a real number.
CArcSec | Returns the complex arcsecant of a complex number.
CArcSecH | Returns the complex hyperbolic arcsecant of a complex number.
CArcSecReal | Returns the complex arcsecant of a real number.
CArcSin | Returns the complex arcsine of a complex number.
CArcSinH | Returns the complex hyperbolic arcsine of a complex number.
CArcSinReal | Returns the complex arcsine of a real number.
CArcTan | Returns the complex arctangent of a complex number.
CArcTanH | Returns the complex hyperbolic arctangent of a complex number.
CArcTanHReal | Returns the complex hyperbolic arctangent of a real number.
CArg | Returns the argument of a complex number.
CArgument | Returns the argument of a complex number.
CASec | Returns the complex arcsecant of a complex number.
CASecH | Returns the complex hyperbolic arcsecant of a complex number.
CASecReal | Returns the complex arcsecant of a real number.
CASin | Returns the complex arcsine of a complex number.
CASinH | Returns the complex hyperbolic arcsine of a complex number.
CASinReal | Returns the complex arcsine of a real number.
CATan | Returns the complex arctangent of a complex number.
CATanH | Returns the complex hyperbolic arctangent of a complex number.
CATanHReal | Returns the complex hyperbolic arctangent of a real number.
CConj | Returns the complex conjugate of a complex number.
CConjugate | Returns the complex conjugate of a complex number.
CCos | Returns the complex cosine of a complex number.
CCosH | Returns the complex hyperbolic cosine of a complex number.
CCot | Returns the complex cotangent of a complex number.
CCotH | Returns the complex hyperbolic cotangent of a complex number.
CCsc | Returns the complex cosecant of thais complex number.
CCscH | Returns the complex hyperbolic cosecant of a complex number.
CDivImag | Divides by an imaginary number.
CDivReal | Divides by a real number.
CExp | Returns the complex exponential of s complex number.
CGetImag | Returns the imaginary part of a complex number.
CGetReal | Returns the real part of a complex number.
CInverse | Returns the inverse, or reciprocal, of a complex number.
CLog | Returns the complex natural logarithm (base e) of s complex number.
CLog10 | Returns the complex base-10 logarithm of a complex number.
CLogAbs | Returns the natural logarithm of the magnitude of a complex number.
CMagnitude | Returns the magnitude of a complex number.
CMod | Returns the modulus of a complex number.
CModulus | Returns the modulus of a complex number.
CMulImag | Multiplies by an imaginary number.
CMulReal | Multiplies by a real number.
CNeg | Negates a complex number.
CNegate | Negates a complex number.
CNegative | Negates the complex number.
CNorm | Returns the squared magnitude of a complex number, otherwise known as the complex norm.
CNthRoot | Returns the kth nth root of a complex number where k = 0, 1, 2, 3,...,n - 1.
CPhase | Returns the argument of a complex number.
CPolar | Sets the complex number from the polar representation.
CPow | Returns this complex number raised to a complex power or to a real number.
CRect | Uses the cartesian components (x,y) to set the real and imaginary parts of the complex number.
CReciprocal | Returns the inverse, or reciprocal, of a complex number.
CSec | Returns the complex secant of a complex number.
CSecH | Returns the complex hyperbolic secant of a complex number.
CSet | Uses the cartesian components (x,y) to set the real and imaginary parts of a complex number.
CSetImag | Sets the imaginary part of a complex number.
CSetReal | Sets the real part of a complex number.
CSgn | Returns the sign of a complex number.
CSin | Returns the complex sine of a complex number.
CSinH | Returns the complex hyperbolic sine of a complex number.
CSqr | Returns the square root of a complex.
CSqrt | Returns the square root of a complex number.
CSqrReal | Returns the complex square root of a real number.
CSubImag | Subtracts an imaginary number.
CSubReal | Subtracts a real number.
CSwap | Exchanges the contents of two complex numbers.
CTan | Returns the complex tangent of a complex number.
CTanH | Returns the complex hyperbolic tangent of a complex number.

### Helper Procedures

Name | Description
--- | ---
acosh | Calculates the inverse hyperbolic cosine.
asinh | Calculates the inverse hyperbolic sine.
atanh | Calculates the inverse hyperbolic tangent of a number.
hypot3 | Computes the value of sqr(x^2 + y^2 + z^2).
IsInfinity | Determines whether the argument is an infinity.

# Comparison operators

Compares complex numbers for equality or inequality.

    OPERATOR = (BYREF z1 AS _complex, BYREF z2 AS _complex) AS BOOLEAN
    OPERATOR <> (BYREF z1 AS _complex, BYREF z2 AS _complex) AS BOOLEAN

#### Example

    DIM c1 AS _complex = (1, 2)
    DIM c2 AS _complex = (3, 4)
    IF c1 = c2 THEN PRINT "equal" ELSE PRINT "different"

# Math operators

    OPERATOR + (BYREF z1 AS _complex, BYREF z2 AS _complex) AS _complex
    OPERATOR + (BYVAL a AS DOUBLE, BYREF z AS _complex) AS _complex
    OPERATOR + (BYREF z AS _complex, BYVAL a AS DOUBLE) AS _complex
    OPERATOR - (BYREF z1 AS _complex, BYREF z2 AS _complex) AS _complex
    OPERATOR - (BYVAL a AS DOUBLE, BYREF z AS _complex) AS _complex
    OPERATOR - (BYREF z AS _complex, BYVAL a AS DOUBLE) AS _complex
    OPERATOR * (BYREF z1 AS _complex, BYREF z2 AS _complex) AS _complex
    OPERATOR * (BYVAL a AS DOUBLE, BYREF z AS _complex) AS _complex
    OPERATOR * (BYREF z AS _complex, BYVAL a AS DOUBLE) AS _complex
    OPERATOR / (BYREF leftside AS _complex, BYREF rightside AS _complex) AS _complex
    OPERATOR / (BYVAL a AS DOUBLE, BYREF z AS _complex) AS _complex
    OPERATOR / (BYREF z AS _complex, BYVAL a AS DOUBLE) AS _complex
    OPERATOR - (BYREF z AS _complex, BYVAL a AS DOUBLE) AS _complex
    OPERATOR ^ (BYREF value AS _complex, BYREF power AS _complex) AS _complex
    OPERATOR ^ (BYREF value AS _complex, BYVAL power AS DOUBLE) AS _complex

#### Examples

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 = c1 + c2
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 = c1 + 11
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 = 11 + c1
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 = c1 - c2
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = c1 - 11
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = 11 - c1
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 = c1 * c2
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = c1 * 11
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = 11 * c1
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 = c1 / c2
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = c1 / 11
    print CStr(c2)

    DIM cpx1 AS _complex = (5, 6)
    DIM cpx2 AS _complex
    cpx2 = 11 / cpx1

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = 11 * c1
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c2 -= c1
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c1 *= c2
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = (5, 6)
    c1 /= c2
    print CStr(c2)

    DIM c1 AS _complex = (3, 4)
    DIM c2 AS _complex = -c1
    print CStr(c2)

# CAbs / CMagnitude

Returns the magnitude of a complex number.

    FUNCTION CAbs (BYREF z AS _complex) AS DOUBLE
    FUNCTION CMagnitude (BYREF z AS _complex) AS DOUBLE

#### Example

    DIM c AS _complex = (2, 3)
    PRINT CAbs(c)
    Output: 3.60555127546399

# CAbs2 / CNorm

Returns the squared magnitude of a complex number, otherwise known as the complex norm.

    FUNCTION CAbs2 () AS DOUBLE
    FUNCTION CNorm () AS DOUBLE

#### Example

    DIM z AS _complex = (2, 3)
    DIM d AS DOUBLE = CAbs2(z)
    PRINT d
    Output: 13
    --or--
    DIM z AS _complex = (2, 3)
    DIM d AS DOUBLE = CNorm(z)
    PRINT d
    Output: 13

# CAbsSqr

Returns the absolute square (squared norm) of a complex number.

    FUNCTION CAbsSqr (BYREF z AS _complex) AS DOUBLE

#### Example

    DIM z AS _complex = (1.2345, -2.3456)
    print CAbsSqr(z)
    Output: 7.025829610000001

# CAddImag

Adds an imaginary number.

    FUNCTION CAddImag (BYREF z AS _complex, BYVAL y AS DOUBLE) AS _complex

Parameter | Description
--- | ---
y | A double value.

#### Example

    DIM c AS _complex = (5, 6)
    c = CAddImag(c, 10)
    print CStr(c)

# CAddReal

Adds a real number.

    FUNCTION CAddReal (BYREF z AS _complex, BYVAL x AS DOUBLE) AS _complex

Parameter | Description
--- | ---
x | A double value.

#### Examples

    DIM c AS _complex = (5, 6)
    c = CAddReal(c, 10)
    print CStr(c)

# CArcCos / CACos

Returns the complex arccosine of a complex number.

    FUNCTION CArcCos (BYREF value AS _complex) AS _complex
    FUNCTION CACos (BYREF value AS _complex) AS _complex

#### Example

    DIM c AS _complex = (1, 1)
    print CStr(CArcCos(c))
    Output: 0.9045568943023814 -1.061275061905036 * i

# CArcCosH / CACosH

Returns the complex hyperbolic arccosine of a complex number. The branch cut is on the real axis, less than 1.

    FUNCTION CArcCosH (BYREF value AS _complex) AS _complex
    FUNCTION CACosH (BYREF value AS _complex) AS _complex

#### Example

    DIM c AS _complex = (1, 1)
    print CStr(CArcCosH(c))
    Output: 1.061275061905036 +0.9045568943023813 * i

# CArcCosHReal / CACosHReal

Returns the complex hyperbolic arccosine of a real number.

    FUNCTION CArcCosHReal (BYVAL value AS DOUBLE) AS _complex
    FUNCTION CACosHReal (BYVAL value AS DOUBLE) AS _complex

Parameter | Description
--- | ---
value | A double value representing the real part of a complex number.

# CArcCosReal / CACosReal

Returns the complex arccosine of a real number.
For a between -1 and 1, the function returns a real value in the range [0, pi].
For a less than -1 the result has a real part of pi and a negative imaginary part.
For a greater than 1 the result is purely imaginary and positive.

    FUNCTION CArcCosReal (BYVAL value AS DOUBLE) AS _complex
    FUNCTION CACosReal (BYVAL value AS DOUBLE) AS _complex

Parameter | Description
--- | ---
value | A double value representing the real part of a complex number.

#### Example

    print CStr(CArcCosReal(1)) ' = 0 0 * i
    print CStr(CArcCosReal(-1)) ' = 3.141592653589793 0 * i
    print CStr(CArcCosReal(2)) ' = 0 +1.316957896924817 * i

# CArcCot / CACot

Returns the complex arccotangent of a complex number.

    FUNCTION CArcCot (BYREF value AS _complex) AS _complex
    FUNCTION CACot (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcCot(z)
    PRINT CStr(z)
    Output: 0.5535743588970452 -0.4023594781085251 * i

# CArcCotH / CACotH

Returns the complex hyperbolic arccotangent of a complex number.

    FUNCTION CArcCotH (BYREF value AS _complex) AS _complex
    FUNCTION CACotH (BYREF value AS _complex) AS _complex

#### Example

    DIM c AS _complex = (1, 1)
    print CStr(CArcCotH(c))
    Output: 0.4023594781085251 -0.5535743588970452 * i

# CArcCsc / CACsc

Returns the complex arccosecant of a complex number.

    FUNCTION CArcCsc (BYREF value AS _complex) AS _complex
    FUNCTION CACsc (BYREF value AS _complex) AS _complex

#### Example

    DIM c AS _complex = (1, 1)
    print CStr(CArcCsc(c))
    Output: 0.4522784471511907 -0.5306375309525178 * i

# CArcCscH / CACscH

Returns the complex hyperbolic arccosecant of a complex number.

    FUNCTION CArcCscH (BYREF value AS _complex) AS _complex
    FUNCTION CACscH (BYREF value AS _complex) AS _complex

#### Example

    DIM c AS _complex = (1, 1)
    print CStr(CArcCscH(c))
    Output: 0.5306375309525179 -0.4522784471511906 * i

# CArcCscReal / CACscReal

Returns the complex arccosecant of a real number.

    FUNCTION CArcCscReal (BYVAL value AS DOUBLE) AS _complex
    FUNCTION CACscReal (BYVAL value AS DOUBLE) AS _complex

#### Example

    print CStr(CArcCscReal(1))
    Output: 1.570796326794897 0 * i

# CArcSec / CASec

Returns the complex arcsecant of a complex number.

    FUNCTION CArcSec (BYREF value AS _complex) AS _complex
    FUNCTION CASec (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcSec(z)
    PRINT CStr(z)
    Output: 1.118517879643706 +0.5306375309525176 * i

# CArcSecH / CASecH

Returns the complex hyperbolic arcsecant of a complex number.

    FUNCTION CArcSecH (BYREF value AS _complex) AS _complex
    FUNCTION CASecH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcSecH(z)
    PRINT CStr(z)
    Output: 0.5306375309525178 -1.118517879643706 * i

# CArcSecReal / CASecReal

Returns the complex arcsecant of a real number.

    FUNCTION CArcSecReal (BYVAL value AS DOUBLE) AS _complex
    FUNCTION CASecReal (BYVAL value AS DOUBLE) AS _complex

Parameter | Description
--- | ---
value | A double value representing the real part of a complex number.

#### Example

    print CStr(CArcSecReal(1.1))
    Output: 0.4296996661514246 0 * i

# CArcSin / CASin

Returns the complex arcsine of a complex number. The branch cuts are on the real axis, less than -1 and greater than 1.

    FUNCTION CArcSin (BYREF value AS _complex) AS _complex
    FUNCTION CASin (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcSin(z)
    PRINT CStr(z)
    Output: 0.6662394324925152 +1.061275061905036 * i

# CArcSinH / CASinH

Returns the complex hyperbolic arcsine of a complex number. The branch cuts are on the imaginary axis, below -i and above i.

    FUNCTION CArcSinH (BYREF value AS _complex) AS _complex
    FUNCTION CASinH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcSinH(z)
    PRINT CStr(z)
    Output: 1.061275061905036 +0.6662394324925153 * i

# CArcSinReal / CASinReal

Returns the complex arcsine of a real number.
For a between -1 and 1, the function returns a real value in the range [-pi/2, pi/2].
For a less than -1 the result has a real part of -pi/2 and a positive imaginary part.
For a greater than 1 the result has a real part of pi/2 and a negative imaginary part.

    FUNCTION CArcSinReal (BYVAL value AS DOUBLE) AS _complex
    FUNCTION CASinReal (BYVAL value AS DOUBLE) AS _complex

Parameter | Description
--- | ---
value | A double value representing the real part of a complex number.

#### Example

    DIM z AS _complex = CArcSinReal(1)
    PRINT CStr(z)
    Output: 1.570796326794897 +0 * i

# CArcTan / CATan

Returns the complex arctangent of a complex number. The branch cuts are on the imaginary axis, below -i and above i.

    FUNCTION CArcTan (BYREF value AS _complex) AS _complex
    FUNCTION CATan (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcTan(z)
    PRINT CStr(z)
    Output: 1.017221967897851 +0.4023594781085251 * i

# CArcTanH / CATanH

Returns the complex hyperbolic arctangent of a complex number. The branch cuts are on the real axis, less than -1 and greater than 1.

    FUNCTION CArcTanH (BYREF value AS _complex) AS _complex
    FUNCTION CATanH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CArcTanH(z)
    PRINT CStr(z)
    Output: 0.4023594781085251 +1.017221967897851 * i

# CArcTanHReal / CATanHReal

Returns the complex hyperbolic arctangent of a real number.

    FUNCTION CArcTanhReal (BYVAL value AS DOUBLE) AS _complex
    FUNCTION CATanhReal (BYVAL value AS DOUBLE) AS _complex

Parameter | Description
--- | ---
value | A double value representing the real part of a complex number.

# CArg / CArgument / CPhase

Returns the argument of this complex number.

    FUNCTION CArg (BYREF z AS _complex) AS DOUBLE
    FUNCTION CArgument (BYREF z AS _complex) AS DOUBLE
    FUNCTION CPhase (BYREF z AS _complex) AS DOUBLE

#### Example

    DIM z AS _complex = (1, 0)
    DIM d AS DOUBLE = CArg(z)
    PRINT d
    Output: 0

    DIM z AS _complex = (0, 1)
    DIM d AS DOUBLE = CArg(z)
    PRINT d
    Output: 1.570796326794897

    DIM z AS _complex = (0, -1)
    DIM d AS DOUBLE = CArg(z)
    PRINT d
    Output: -1.570796326794897

    DIM z AS _complex = (-1, 0)
    DIM d AS DOUBLE = CArg(z)
    PRINT d
    Output: 3.141592653589793

# CConjugate / CConj

Returns the complex conjugate of a complex number.

    FUNCTION CConjugate (BYREF z AS _complex) AS _complex
    FUNCTION CConj (BYREF z AS _complex) AS _complex

#### Example

    DIM z AS _complex = (2, 3)
    z = CConj(z)
    PRINT CStr(z)
    Output: 2 - 3 * i

# CCos

Returns the complex cosine of a complex number.

    FUNCTION CCos (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CCos(z)
    PRINT CStr(z)
    Output: 0.8337300251311491 -0.9888977057628651 * i

# CCosH

Returns the complex hyperbolic cosine of a complex number.

    FUNCTION CCosH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CCosH(z)
    PRINT CStr(z)
    Output: 0.8337300251311491 +0.9888977057628651 * i

# CCot

Returns the complex cotangent of a complex number.

    FUNCTION CCot (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CCot(z)
    PRINT CStr(z)
    Output: 0.2176215618544027 -0.8680141428959249 * i

# CCotH

Returns the complex hyperbolic cotangent of a complex number.

    FUNCTION CCotH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CCotH(z)
    PRINT CStr(z)
    Output: 0.8680141428959249 -0.2176215618544029 * i

# CCsc

Returns the complex cosecant of a complex number.

    FUNCTION CCsc (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CCsc(z)
    PRINT CStr(z)
    Output: 0.6215180171704285 -0.3039310016284265 * i

# CCscH

Returns the complex hyperbolic cosecant of a complex number.

    FUNCTION CCscH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CCscH(z)
    PRINT CStr(z)
    Output: 0.3039310016284265 -0.6215180171704285 * i

# CDivImag

Divides by an imaginary number.

    FUNCTION CDivImag (BYREF z AS _complex, BYVAL y AS DOUBLE) AS _complex

Parameter | Description
--- | ---
y | A double value.

# CDivReal

Divides by a real number.

    FUNCTION CDivReal (BYREF z AS _complex, BYVAL x AS DOUBLE) AS _complex

Parameter | Description
--- | ---
x | A double value.

# CExp

Returns the complex exponential of a complex number.

    FUNCTION CExp (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CExp(z)
    PRINT CStr(z)
    Output: 1.468693939915885 +2.287355287178842 * i

# CGetImag

Returns the imaginary part of a complex number.

    FUNCTION CGetImag (BYREF z AS _complex) AS DOUBLE

# CGetReal

Returns the real part of a complex number.

    FUNCTION CGetReal (BYREF z AS _complex) AS DOUBLE

# CLog

Returns the complex natural logarithm (base e) of a complex number. The branch cut is the negative real axis.

    FUNCTION CLog OVERLOAD (BYREF value AS _complex) AS _complex
    FUNCTION CLog OVERLOAD (BYREF value AS _complex, BYVAL baseValue AS DOUBLE) AS _complex

Parameter | Description
--- | ---
baseValue | A double value.

#### Examples

    DIM z AS _complex = (1, 1)
    z = CLog(z)
    PRINT CStr(z)
    Output: 0.3465735902799727 +0.7853981633974483 * i

    DIM z AS _complex = (0, 0)
    z = CLog(z)
    PRINT CStr(z)
    Output: -1.#INF

    DIM z AS _complex = (1, 1)
    z = CLog(z, 10)
    PRINT CStr(z)
    Output: 0.1505149978319906 +0.3410940884604603 * i

# CLog10

Returns the complex base-10 logarithm of a complex number.

    FUNCTION CLog10 (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CLog10(z)
    PRINT CStr(z)
    Output: 0.1505149978319906 +0.3410940884604603 * i

# CLogAbs

Returns the natural logarithm of the magnitude of the complex number z, log|z|. It allows an accurate evaluation of \log|z| when |z| is close to one. The direct evaluation of log(CAbs(z)) would lead to a loss of precision in this case.

    FUNCTION CLogAbs (BYREF value AS _complex) AS DOUBLE

#### Example

    DIM z AS _complex = (1.1, 0.1)
    DIM d AS DOUBLE = CLogAbs(z)
    print d
    Output: 0.09942542937258279

# CModulus / CMod

Returns the modulus of a complex number.

    FUNCTION CModulus (BYREF z AS _complex) AS DOUBLE
    FUNCTION CMod (BYREF z AS _complex) AS DOUBLE

#### Example

    DIM z AS _complex = (2.3, -4.5)
    print CModulus(z)
    Output: 5.053711507397311

    DIM z AS _complex = CPolar(0.2938, -0.5434)
    print CModulus(z)
    Output: 0.2938

# CMulImag

Multiplies by an imaginary number.

    FUNCTION CMulImag (BYREF z AS _complex, BYVAL y AS DOUBLE) AS _complex

Parameter | Description
--- | ---
y | A double value.

#### Example

    DIM z AS _complex = (5, 6)
    z = CMulImag(z, 3)
    PRINT CStr(z)

# CMulReal

Multiplies by a real number.

    FUNCTION CMulReal (BYREF z AS _complex, BYVAL x AS DOUBLE) AS _complex

Parameter | Description
--- | ---
x | A double value.

#### Example

    DIM z AS _complex = (5, 6)
    z = CMulReal(z, 3)
    PRINT CStr(z)

# CNegate / CNeg / CNegative

Negates the complex number.

    FUNCTION CNeg (BYREF z AS _complex) AS _complex
    FUNCTION CNegate (BYREF z AS _complex) AS _complex
    FUNCTION CNegative (BYREF z AS _complex) AS _complex

# CNthRoot

Returns the kth nth root of a complex number where k = 0, 1, 2, 3,...,n - 1.
De Moivre's formula states that for any complex number x and integer n it holds that
cos(x)+ isin(x))^n = cos(nx) + isin(nx)
where i is the imaginary unit (i2 = -1).
Since z = re^(it) = r * (cos(t) + i sin(t))
where
z = (a, ib)
r = modulus of z
t = argument of z
i = sqrt(-1.0)
we can calculate the nth root of z by the formula:
z^(1/n) = r^(1/n) * (cos(x/n) + i sin(x/n))
by using log division.

    FUNCTION CNthRoot (BYREF z AS _complex, BYVAL n AS LONG, BYVAL k AS LONG = 0) AS _complex

#### Example

    DIM z AS _complex = (2.3, -4.5)
    DIM n AS LONG = 5
    FOR i AS LONG = 0 TO n - 1
       print CStr(CNthRoot(z, n, i))
    NEXT
    Output:
     1.349457704883236  -0.3012830564679053 * i
     0.7035425781022545 +1.190308959128094 * i
    -0.9146444790833151 +1.036934450322577 * i
    -1.268823953798186  -0.5494482247230521 * i
     0.1304681498960107 -1.376512128259714 * i

# CPolar

Sets the complex number from the polar representation.

    FUNCTION CPolar (BYVAL r AS DOUBLE, BYVAL theta AS DOUBLE) AS _complex

Parameter | Description
--- | ---
r | The modulus of complex number.
theta | The angle with the positive direction of x-axis.

#### Example

    DIM z AS _complex = CPolar(3, 4)

# CPow

Returns this complex number raised to a complex power.
Returns this complex number raised to a real number.

    FUNCTION CPow OVERLOAD (BYREF value AS _complex, BYREF power AS _complex) AS _complex
    FUNCTION CPow OVERLOAD (BYREF value AS _complex, BYVAL power AS DOUBLE) AS _complex

Parameter | Description
--- | ---
power | A complex or a double number.

#### Examples

    DIM z AS _complex = (1, 1)
    DIM b AS _complex = (2, 2)
    print CStr(CPow(z, b))
    Output: -0.2656539988492412 +0.3198181138561362 * i

    DIM z AS _complex = (1, 1)
    PRINT CStr(CPow(z, 2))
    Output: 1.224606353822378e-016 +2 * i

# CReciprocal / CInverse

Returns the inverse, or reciprocal, of a complex number.

    FUNCTION CReciprocal (BYREF value AS _complex) AS _complex
    FUNCTION CInverse (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CReciprocal(z)
    PRINT CStr(z)
    Output: 0.5 -0.5 * i

# CSec

Returns the complex secant of a complex number.

    FUNCTION CSec (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CSec(z)
    PRINT CStr(z)
    Output: 0.4983370305551869 +0.591083841721045 * i

# CSecH

Returns the complex hyperbolic secant of a complex number.

    FUNCTION CSecH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CSecH(z)
    PRINT CStr(z)
    Output: 0.4983370305551869 -0.591083841721045 * i

# CSet / CRect

Uses the cartesian components (x,y) to set the real and imaginary parts of the complex number.

    FUNCTION CSet (BYVAL x AS DOUBLE, BYVAL y AS DOUBLE) AS _complex
    FUNCTION CRet (BYVAL x AS DOUBLE, BYVAL y AS DOUBLE) AS _complex

Parameter | Description
--- | ---
x, y | Double values.

#### Example

    DIM z AS _complex = CSet(3, 4)

# CSetImag

Sets the imaginary part of a complex number.

    SUB CSetImag (BYREF z AS _complex, BYVAL y AS DOUBLE)

Parameter | Description
--- | ---
z | The complex number.
y | A double value.

# CSetReal

Sets the real part of a complex number.

    SUB CSetReal (BYREF z AS _complex, BYVAL y AS DOUBLE)

Parameter | Description
--- | ---
z | The complex number.
y | A double value.

# CSgn

Returns the sign of this complex number.
If number is greater than zero, then CSgn returns 1.
If number is equal to zero, then CSgn returns 0.
If number is less than zero, then CSgn returns -1.

    FUNCTION CSgn (BYREF z AS _complex) AS LONG

# CSin

Returns the complex sine of a complex number.

    FUNCTION CSin (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CSin(z)
    PRINT CStr(z)
    Output: 1.298457581415977 +0.6349639147847361 * i

# CSinH

Returns the complex hyperbolic sine of a complex number.

    FUNCTION CSinH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CSinH(z)
    PRINT CStr(z)
    Output: 0.6349639147847361 +1.298457581415977 * i

# CSqr / CSqrt

Returns the square root of the complex number z. The branch cut is the negative real axis. The result always lies in the right half of the complex plane.

    FUNCTION CSqr (BYREF value AS _complex) AS _complex
    FUNCTION CSqrt (BYREF value AS _complex) AS _complex

Parameter | Description
--- | ---
value | A complex number.

#### Examples

    DIM z AS _complex = (2, 3)
    z = CSqr(z)
    PRINT CStr(z)
    Output: 1.67414922803554 +0.895977476129838 * i

Compute the square root of -1:

    DIM z AS _complex = (-1)
    z = CSqr(z)
    PRINT CStr(z)
    Output: 0 +1.0 * i

# CSqrReal

Returns the complex square root of the real number x, where x may be negative.

    FUNCTION CSqrReal (BYVAL value AS DOUBLE) AS _complex

Parameter | Description
--- | ---
value | A double value representing a real number.

# CSubImag

Subtracts an imaginary number.

    FUNCTION CSubImag (BYREF z AS _complex, BYVAL y AS DOUBLE) AS _complex

Parameter | Description
--- | ---
y | A double value.

#### Example

    DIM z AS _complex = (5, 6)
    z = CSubImag(z, 3)
    PRINT CStr(z)
    Output:  5 +3 * i

# CSubReal

Subtracts a real number.

    FUNCTION CSubReal (BYREF z AS _complex, BYVAL x AS DOUBLE) AS _complex

Parameter | Description
--- | ---
x | A double value.

#### Example

    DIM z AS _complex = (5, 6)
    z = CSubReal(z, 2)
    PRINT CStr(z)
    Output: 3 +6 * i

# CSwap

Exchanges the contents of two complex numbers.

    SUB CSwap (BYREF z1 AS _complex, BYREF z2 AS _complex)

Parameter | Description
--- | ---
z1 / z2 | The complex numbers to swap.

# CTan

Returns the complex tangent of a complex number.

    FUNCTION CTan (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CTan(z)
    PRINT CStr(z)
    Output: 0.2717525853195117 +1.083923327338695 * i

# CTanH

Returns the complex hyperbolic tangent of a complex number.

    FUNCTION CTanH (BYREF value AS _complex) AS _complex

#### Example

    DIM z AS _complex = (1, 1)
    z = CTanH(z)
    PRINT CStr(z)
    Output: 1.083923327338695 +0.2717525853195119 * i

# acosh

Calculates the inverse hyperbolic cosine.

    FUNCTION acosh (BYVAL x AS DOUBLE) AS DOUBLE

Parameter | Description
--- | ---
x | A double value.

# asinh

Calculates the inverse hyperbolic sine.

    FUNCTION asinh (BYVAL x AS DOUBLE) AS DOUBLE

Parameter | Description
--- | ---
x | A double value.

# atanh

Returns the inverse hyperbolic tangent of a number.

    FUNCTION atanh (BYVAL x AS DOUBLE) AS DOUBLE

Parameter | Description
--- | ---
x | A double value.

# hypot3

Computes the value of sqr(x^2 + y^2 + z^2).

    FUNCTION hypot3 (BYVAL x AS DOUBLE, BYVAL y AS DOUBLE, BYVAL z AS DOUBLE) AS DOUBLE

Parameter | Description
--- | ---
x, y, z | Double values.

# IsInfinity / IsInf

Determines whether the argument is an infinity.

    FUNCTION IsInfinity (BYVAL x AS DOUBLE) AS LONG
    FUNCTION IsInf (BYVAL x AS DOUBLE) AS LONG

Parameter | Description
--- | ---
x | A double value.

#### Remarks

Returns +1 if x is positive infinity, -1 if x is negative infinity and 0 otherwise.