Datatype complex
Complex numbers are the most important numbers in ChaosPro: The whole fractal calculation is done using complex numbers, so one of the main reasons of writing the compiler was to natively support such a datatype.
Complex numbers consist of two floating point numbers, the one being called “real part”, the other one being called “imaginary part”. Writing down a complex number is done either by surrounding the two floating point numbers by parenthesis or by using the “imaginary 1″, called “i”.
So you can use any of the following syntaxes:
a = (1.2,-1.3); // surrounded by brackets, separated by comma a = (1.2/-1.3); // surrounded by brackets, separated by / a = 1.2+1.3i; // using the imaginary "1", i.e. "i". Note that "i"=(0,1) a = 1.2+i*1.3; // using "i" in front of the imaginary part
Complex numbers are stored internally as two floating point numbers which use the 80 bit FPU format (internal coprocessor format), with 14 bit exponent and 64 bit mantissa. So each component of a complex number has the same precision as a real number.
Future versions of ChaosPro will perhaps allow you to use double or float for the two floating point numbers.
Converting to/from complex numbers
Complex numbers are converted automatically to other datatypes if necessary and allowed.
Converting to:
- bool: imaginary part of complex number is neglegated. If real part of complex number is 0, then the bool will be false, otherwise true.
- int: real part of complex number gets rounded towards zero.
- real: real part of complex number will be taken.
- quaternion: real and imaginary part of quaternion number get the real and imaginary part of the complex number, “j” and “k” part of quaternion number will be 0.
Converting from:
- bool: false gets converted to (0,0), true gets converted to (1,0).
- int: real part of complex number gets this value, imaginary part is set to 0.
- real: real part of complex number gets this value, imaginary part is set to 0.
- quaternion: real and imaginary part of complex number get the real and imaginary part of the quaternion number.