NAME

src/pmc/bignum.pmc - BigNum PMC class

DESCRIPTION

BigNum provides arbitrary precision floating point mathematic functions, based on the GMP mpf library.

SYNOPSIS

Make mixing of classes work, like in:

        new $P0 ['BigInt']
        new $P1 ['BigNum']
        set $P0, 10
        set $P1, 2
        div P2, P0, P1  # $P2 = $P0 / $P1; (BigNum) 5.0

Make auto-upgrading/downgrading work.

        set $N1, $P0
        set $N1, $P1
        set $I1, $P0
        set $I1, $P1
        set $P0, $I1
        set $P0, $N1
        set $P1, $I1
        set $P1, $N1

  BigNum
    => BigInt => Integer
    => Number: float (can be long double) and double
    => Integer (unsigned long)

Functions

static void bignum_set(Interp*, PMC *, PMC *)
static void bignum_set_si(Interp*, PMC *, long value)
static void bignum_set_double(Interp*, PMC *, double value)
static void bignum_set_str(Interp*, PMC *, char *, int base)

Methods

METHOD version()
Return GMP version string "x.y.z".
PMC *instantiate(PMC *sig)
Object constructor. SELF is a BigNum Class object. Return a new BigNum object.
void set_integer_native(INTVAL value)
void set_number_native(FLOATVAL value)
Sets the value of the BigNum to value.
void set_string_native(STRING *value)
Sets the value of the BigNum to the result of converting *value to a number.
void set_string_keyed_int(INTVAL base, STRING *value)
Same assume number base base.
void set_pmc(PMC *value)
Sets the value of the BigNum to the BigNum value of *value.
FLOATVAL get_number()
Down-converts the precise BigNum to an imprecise double.
INTVAL get_integer()
Returns the integer conversion of the BigNum.
INTVAL get_ulong()
Returns the unsigned long conversion of the BigNum.
PMC *get_bignum()
Returns SELF, keeping floating point precision.
FLOATVAL get_bigint()
Trunc the BigNum to an BigInt.
INTVAL get_bool()
Returns the boolean value of the BigNum.
STRING *get_string()
Returns the string representation of the BigNum.
STRING *get_string_keyed_int(INTVAL base)
Returns the string representation of the BigNum in base base.
STRING *get_string_keyed_int_int(INTVAL base, INTVAL digits)
Returns the string representation of the BigNum in base base with digits digits.
STRING *get_repr()
Returns the string representation of the BigNum with the letter 'N' appended.
void increment()
Increment the BigNum by 1.0.
void decrement()
Decrement the BigNum by 1.0.
void add()
void substract()
void multiply()
void pow()
void divide()
void floor_divide()
void cmp()
void is_equal()
PMC *absolute(PMC *dest)
void i_absolute()
Sets dest to the absolute value of SELF.
PMC *neg(PMC *dest)
void i_neg()
Set dest to the negated value of SELF.