Complex number - chung-leong/qb GitHub Wiki

In QB, complex numbers are represented as a two-element arrays of either float32 or float64. Beginning with QB v.2.3, you can use declare a variable to be of the type complex<float32> or complex<float64>. Doing so changes the behaviors of mathematical operators. For instance, multiplication between two arrays, $a * $b, normally means multiplication of the of elements contained within. When either $a or $b is declared to be complex, the operation is interpreted instead as a multiplication of two complex number. It becomes equivalent to cmult($a, $b).

Trigonometric functions are similarly "overloaded". When $a is float32[2], sin($a) returns an array containing sin($a[0]) and sin($a[1]). When $a is complex<float32>, sin($a) returns csin($a).

complex on its own--without the type identifier--implies complex<float32>.

When a variable is declared to be complex, the real part of the complex number can be accessed as $a->r while the imaginary part can be accessed as $a->i. It is equivalent to accessing the array elements through numeric indices, i.e. $a[0] and $a[1].

⚠️ **GitHub.com Fallback** ⚠️