NAME

src/pmc/complex.pmc - Complex PMC

DESCRIPTION

`Complex` provides a representation of complex numbers. It handles string parsing/generating and basic mathematical operations.

Functions

Equations used are sometimes listed. At times, multiple equations are given, but those starting with => are the ones used.

`static void complex_parse_string(PARROT_INTERP, FLOATVAL *re, FLOATVAL *im, STRING *value)`
Parses the string in `value` to produce a complex number, represented by the real (`*re`) and imaginary (`*im`) parts. Raises an exception if it cannot understand the string. The string should be of the form `a+bi` with optional spaces around `+` and before `i`. You can also use `j` instead of `i`.
`static void int_check_divide_zero(PARROT_INTERP, INTVAL value)`
If `value` is 0, throw a divide by zero exception.
`static void float_check_divide_zero(PARROT_INTERP, FLOATVAL value)`
If `value` is 0.0, throw a divide by zero exception.
`static void complex_check_divide_zero(PARROT_INTERP, PMC *value)`
If `value` is a Complex PMC with a value of 0, throw a divide by zero exception.

Methods

`void init()`
Initializes the complex number with the value 0+0i.
`void init_pmc(PMC *initializer)`
Initializes the complex number with the specified initializer. The initializer can be a string PMC or a numeric array with (real, imag)
`PMC *clone()`
Creates an identical copy of the complex number.
`void freeze(PMC *visit)`
`void thaw(PMC *visit)`
Serialize/deserialize this object for bytecode.
`INTVAL get_integer()`
Returns the modulus of the complex number as an integer.
`FLOATVAL get_number()`
Returns the modulus of the complex number.
`STRING *get_string()`
Returns the complex number as a string in the form `a+bi`.
`INTVAL get_bool()`
Returns true if the complex number is non-zero.
`INTVAL get_integer_keyed(PMC *key)`
`INTVAL get_integer_keyed_str(STRING *key)`
`FLOATVAL get_number_keyed(PMC *key)`
`FLOATVAL get_number_keyed_str(STRING *key)`
`PMC *get_pmc_keyed(PMC *key)`
`PMC *get_pmc_keyed_str(STRING *key)`
Returns the requested number (real part for `real` and imaginary for `imag`).
`PMC *get_pmc_keyed_int(INTVAL key)`
Returns the requested number (real part for `0` and imaginary for `1`).
`FLOATVAL get_number_keyed_int(INTVAL key)`
Quick hack to emulate get_real() and get_imag():
```  key = 0 ... get real part
key = 1 ... get imag part```
`void set_number_keyed_int(INTVAL key, FLOATVAL v)`
Set real or imag depending on key
`void set_string_native(STRING *value)`
Parses the string `value` into a complex number; raises an exception on failure.
`void set_pmc(PMC *value)`
if `value` is a Complex PMC then the complex number is set to its value; otherwise `value`'s string representation is parsed with `set_string_native()`.
`void set_integer_native(INTVAL value)`
`void set_number_native(FLOATVAL value)`
Sets the real part of the complex number to `value` and the imaginary part to `0.0`
`void set_integer_keyed(PMC *key, INTVAL value)`
`void set_integer_keyed_str(STRING *key, INTVAL value)`
`void set_number_keyed(PMC *key, FLOATVAL value)`
`void set_number_keyed_str(STRING *key, FLOATVAL value)`
`void set_pmc_keyed(PMC *key, PMC *value)`
`void set_pmc_keyed_str(STRING *key, PMC *value)`
Sets the requested number (real part for `real` and imaginary for `imag`) to `value`.
`PMC *add(PMC *value, PMC *dest)`
`PMC *add_int(INTVAL value, PMC *dest)`
`PMC *add_float(FLOATVAL value, PMC *dest)`
Adds `value` to the complex number, placing the result in `dest`.
`PMC *subtract(PMC *value, PMC *dest)`
`PMC *subtract_int(INTVAL value, PMC *dest)`
`PMC *subtract_float(FLOATVAL value, PMC *dest)`
Subtracts `value` from the complex number, placing the result in `dest`.
`PMC *multiply(PMC *value, PMC *dest)`
`PMC *multiply_int(INTVAL value, PMC *dest)`
`PMC *multiply_float(FLOATVAL value, PMC *dest)`
Multiplies the complex number with `value`, placing the result in `dest`.
`void i_multiply(PMC *value)`
`void i_multiply_int(INTVAL value)`
`void i_multiply_float(FLOATVAL value)`
Multiplies the complex number SELF inplace with `value`.
`PMC *divide(PMC *value, PMC *dest)`
`PMC *divide_int(INTVAL value, PMC *dest)`
`PMC *divide_float(FLOATVAL value, PMC *dest)`
Divide the complex number by `value`, placing the result in `dest`.
`void i_divide(PMC *value, PMC *dest)`
`void i_divide_int(INTVAL value, PMC *dest)`
`void i_divide_float(FLOATVAL value, PMC *dest)`
Divide the complex number `SELF` by `value` inplace.Throws divide by zero exception if divisor is zero.
`PMC *neg(PMC *dest)`
`void neg()`
Set `dest` to the negated value of `SELF`.
`INTVAL is_equal(PMC *value)`
Compares the complex number with `value` and returns true if they are equal.
`PMC *absolute(PMC *dest)`
`void i_absolute()`
Sets `dest` to the absolute value of SELF that is the distance from (0.0).
`METHOD ln()`
Returns the natural logarithm of SELF as a PMC.
`METHOD exp()`
Returns e ^ SELF as a PMC.
`METHOD PMC *sin()`
`METHOD PMC *cos()`
`METHOD PMC *tan()`
`METHOD PMC *csc()`
`METHOD PMC *sec()`
`METHOD PMC *cot()`
Returns `FUNC`(SELF).
`METHOD PMC *asin()`
`METHOD PMC *acos()`
`METHOD PMC *atan()`
`METHOD PMC *acsc()`
`METHOD PMC *asec()`
`METHOD PMC *acot()`
Returns the inverse function of SELF.
`METHOD PMC *sinh()`
Returns the arctangent of SELF.
`METHOD PMC *cosh()`
Returns the arcsine of SELF.
`METHOD PMC *tanh()`
Returns the arccosine of SELF.
`METHOD PMC *asinh()`
`METHOD PMC *acosh()`
`METHOD PMC *atanh()`
`METHOD PMC *acsch()`
`METHOD PMC *asech()`
`METHOD PMC *acoth()`
The inverse hyperbolic functions. Currently all broken, but for `func(a+bi) = c+di`, `|c|` and `|d|` will be correct, confusingly enough.
`METHOD PMC *pow(PMC *value)`
Raise SELF to the power of value. Replacement for the old pow() vtable, which was deleted.TODO: Requires testing
`METHOD PMC *sqrt()`
Return the square root of SELF.