NAME
src/dynpmc/rational.pmc - Rational numbers PMC
DESCRIPTION
Rational is currently going to get implemented. It uses the GNU Multiple Precision (GMP) library, like BigInt, because implementation with integers would be too unstable and inaccurate.
'LispRational' will subclass this.
You may use Rational with any of parrot's basic data types as well as with String-, Integer- and Float-PMCs.
Functions
Currently rational.pmc
only has some static
functions for code sharing.
- static STRING *rat_get_string_to_base(PARROT_INTERP, PMC *self, int base)
- static void rat_add_integer(PARROT_INTERP, PMC *self, int value)
- static void rat_add_float(PARROT_INTERP, PMC *self, double value)
- static void rat_multiply_integer(PARROT_INTERP, PMC *self, int value)
- static void rat_multiply_float(PARROT_INTERP, PMC *self, double value)
- static void rat_divide_integer(PARROT_INTERP, PMC *self, int value)
- static void rat_divide_float(PARROT_INTERP, PMC *self, double value)
Returns a string representation of a Rational-PMC to a certain base.
Adds an integer "value" to a Rational-PMC inplace.
Adds a float "value" to a Rational-PMC in-place. "value" is first conveted to a rational using GMPs mpq_set_d-function. This is meant to be exact.
Multiplys a Rational-PMC with an integer "value" in-place.
Multiplies a Rational-PMC with a float "value" in-place.
Divides a Rational-PMC through an integer "value" in-place.
Divides a Rational-PMC through a float "value" in-place.
Methods
The DynPMC Rational has the following methods. Note, that all methods depend on GMP. If GMP is not available, an exception is thrown in almost all cases. The only exception is the version-method.
METHOD version()
Returns the version of GNU Multiple Precision library.
Returns 0.0.0,
if GMP is not available.
void init()
void clone()
void destroy()
void set_integer_native(INTVAL)
void set_number_native(FLOATVAL)
void set_string_native(STRING*)
void set_string_keyed_int(INTVAL base, STRING *value)
INTVAL get_integer()
get_number()
get_bool()
STRING *get_string()
STRING *get_string_keyed_int(INTVAL base)
void increment()
void decrement()
PMC *add(PMC* value, PMC* dest)
Adds Integer-,
Float- or Rational-PMCs to SELF and stores them in dest.
void i_add(PMC *value)
PMC *add_int(INTVAL value, PMC* dest)
void i_add_int(INTVAL value)
PMC *add_float(FLOATVAL value, PMC* dest)
void i_add_float(FLOATVAL value)
PMC *subtract(PMC* value, PMC* dest)
void i_subtract(PMC *value)
PMC *subtract_int(INTVAL value, PMC* dest)
void i_subtract_int(INTVAL value)
PMC *subtract_float(FLOATVAL value, PMC* dest)
void i_subtract_float(FLOATVAL value)
PMC *multiply(PMC* value, PMC* dest)
void i_multiply(PMC *value)
PMC *multiply_int(INTVAL value, PMC* dest)
void i_multiply_int(INTVAL value)
PMC *multiply_float(FLOATVAL value, PMC* dest)
void i_multiply_float(FLOATVAL value)
PMC *divide(PMC* value, PMC* dest)
void i_divide(PMC *value)
PMC *divide_int(INTVAL value, PMC* dest)
void i_divide_int(INTVAL value)
PMC *divide_float(FLOATVAL value, PMC* dest)
void i_divide_float(FLOATVAL value)
PMC *negate(PMC* dest)
void i_negate()
PMC *absolute(PMC* dest)
void i_absolute()
INTVAL cmp(PMC *value)
INTVAL is_equal(PMC *value)