Module Std.Complex


module Complex: sig .. end
Overloading and optimizations for the Complex module.

val overloading : Delimited_overloading.t
In addition to the features listed at the top of this module, overloading_complex allows the notation I or i to designate the pure imaginary complex number and x I, where x is a literal integer or float, to mean x times I. Expressions like
        a + bI
        
where a and b are float of integer literals, are transformed into { Complex.re = a; Complex.im = b }. The functions **, conj, norm, norm2, arg, sin, cos, exp, log are also overloaded and can be used without prefixing them by Complex.. abs (resp. abs2) can be used as an alias for norm (resp. norm2). Comparison operators <=, <, >=, > can be used (it is assumed their operand is real; if it can be detected that one is complex, a parsing error is raised).

You can use z.re and z.im, where z is a complex expression, to take the real and imaginary parts of z. Two "inverse" functions are provided: re : float -> Complex.t (resp. im : float -> Complex.t) that takes a float x to a complex with real (resp. imginary) part x. Operations are optimized so that writing re x + im y or re x + re y * I is equivalent to {Complex.re = x; im = y}.

The expression float z will return the float contained in the complex z. Expressions like arg z or norm z return real numbers embedded in the complex type, you must write float(arg z) to "convert" them to float. If it cannot be determined from the expression that it is real (like float z.re or float(arg ...)), a parsing exception will be raised. Note that inequalities have the same behavior, so you can write norm z <= 3 and the right code will be generated.

Complex expressions written with these overloadings are never be less efficient that the ones written with the complex module.

Remark: The literal -0-0I means (-0)+(-0)I and so is the complex number { Complex.re = (-0.); im = (-0.)}. The sign of zeros is important for some complex operations.