Wikifunctions:Type proposals/complex128
Summary
A complex128 is simply a pair of float64.
Uses
Structure
Either stored as a pair of float64, or as a string. If the latter, we also need to consider whether to use i or j to represent the imaginary unit.
Example values
Value 0
{
"type": "complex128",
"real part": {
"type": "float64",
"value": "0.0"
},
"imaginary part": {
"type": "float64",
"value": "0.0"
}
}
|
{
"Z1K1": "Zxx",
"ZxxK1": {
"Z1K1": "Zyy",
"ZyyK1": "0.0"
},
"ZxxK2": {
"Z1K1": "Zyy",
"ZyyK1": "0.0"
}
}
|
Persistent objects
At least we should have an object for i.
Validator
The validator ensures that:
- real part and imaginary part are valid float64
Identity
Similar to Wikifunctions:Type proposals/float64
Converting to code
Python
For example: (3+5j).imag=5.0
JavaScript
JavaScript does not natively support complex number, so we have to represent it as an object.
Renderer
We can display it as a+bj format.
Parsers
First extract a and b (we may also have a-bj or only bj), then parse a and b as float64.
Alternatives
We can have a general type for complex number whose real and imaginary part are specific number type. This can be used to express e.g. Gaussian integer.