Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reverting to 84e0c30

  • Loading branch information...
commit 7edf9b96724ed76bf2ded93a3264f04d4566373a 1 parent ea10b13
@petdance petdance authored
Showing with 45 additions and 71 deletions.
  1. +45 −71 src/dynpmc/rational.pmc
View
116 src/dynpmc/rational.pmc
@@ -54,7 +54,7 @@ Returns a string representation of a Rational-PMC to a certain base.
*/
static STRING *rat_get_string_to_base(PARROT_INTERP, PMC *self, int base) {
#ifdef PARROT_HAS_GMP
- char * const cstr = mpq_get_str(NULL, base, RT(self));
+ char * const cstr = mpq_get_str(NULL, (int) base, RT(self));
STRING * const pstr = Parrot_str_new(interp, cstr, 0);
Parrot_str_free_cstring(cstr);
return pstr;
@@ -72,11 +72,11 @@ Adds an integer "value" to a Rational-PMC inplace.
=cut
*/
-static void rat_add_integer(PMC *self, int value) {
+static void rat_add_integer(PARROT_INTERP, PMC *self, int value) {
#ifdef PARROT_HAS_GMP
mpq_t t;
mpq_init(t);
- mpq_set_si(t, value, 1);
+ mpq_set_si(t, (int) value, 1);
mpq_add(RT(self), RT(self), t);
mpq_clear(t);
#else
@@ -94,12 +94,12 @@ rational using GMPs mpq_set_d-function. This is meant to be exact.
=cut
*/
-static void rat_add_float(PMC *self, double value) {
+static void rat_add_float(PARROT_INTERP, PMC *self, double value) {
#ifdef PARROT_HAS_GMP
mpq_t t;
mpq_init(t);
- mpq_set_d(t, value);
+ mpq_set_d(t, (double) value);
mpq_add(RT(self), RT(self), t);
mpq_clear(t);
#else
@@ -116,7 +116,7 @@ Multiplies a Rational-PMC with an integer "value" in-place.
=cut
*/
-static void rat_multiply_integer(PMC *self, int value) {
+static void rat_multiply_integer(PARROT_INTERP, PMC *self, int value) {
#ifdef PARROT_HAS_GMP
mpz_mul_ui(mpq_numref(RT(self)), mpq_numref(RT(self)), (unsigned int) value);
#else
@@ -133,12 +133,12 @@ Multiplies a Rational-PMC with a float "value" in-place.
=cut
*/
-static void rat_multiply_float(PMC *self, double value) {
+static void rat_multiply_float(PARROT_INTERP, PMC *self, double value) {
#ifdef PARROT_HAS_GMP
mpq_t t;
mpq_init(t);
- mpq_set_d(t, value);
+ mpq_set_d(t, (double) value);
mpq_mul(RT(self), RT(self), t);
mpq_clear(t);
#else
@@ -155,12 +155,12 @@ Divides a Rational-PMC through an integer "value" in-place.
=cut
*/
-static void rat_divide_integer(PMC *self, int value) {
+static void rat_divide_integer(PARROT_INTERP, PMC *self, int value) {
#ifdef PARROT_HAS_GMP
mpq_t t;
mpq_init(t);
- mpq_set_si(t, value, 1);
+ mpq_set_si(t, (int) value, 1);
mpq_div(RT(self), RT(self), t);
mpq_clear(t);
#else
@@ -177,12 +177,12 @@ Divides a Rational-PMC through a float "value" in-place.
=cut
*/
-static void rat_divide_float(PMC *self, double value) {
+static void rat_divide_float(PARROT_INTERP, PMC *self, double value) {
#ifdef PARROT_HAS_GMP
mpq_t t;
mpq_init(t);
- mpq_set_d(t, value);
+ mpq_set_d(t, (double) value);
mpq_div(RT(self), RT(self), t);
mpq_clear(t);
#else
@@ -285,7 +285,6 @@ Returns the version of GNU Multiple Precision library. Returns 0.0.0, if GMP is
*/
VTABLE void set_integer_native(INTVAL value) {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpq_set_si(RT(SELF), (signed int) value, 1);
mpq_canonicalize(RT(SELF));
#else
@@ -302,7 +301,6 @@ Returns the version of GNU Multiple Precision library. Returns 0.0.0, if GMP is
*/
VTABLE void set_number_native(FLOATVAL value) {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpq_set_d(RT(SELF), (double) value);
mpq_canonicalize(RT(SELF));
#else
@@ -384,7 +382,6 @@ Returns the version of GNU Multiple Precision library. Returns 0.0.0, if GMP is
VTABLE FLOATVAL get_number() {
#ifdef PARROT_HAS_GMP
const double d = mpq_get_d(RT(SELF));
- UNUSED(INTERP)
return (FLOATVAL) d;
#else
RAISE_EXCEPTION
@@ -447,7 +444,6 @@ Returns the version of GNU Multiple Precision library. Returns 0.0.0, if GMP is
*/
VTABLE void increment() {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpz_add(mpq_numref(RT(SELF)), mpq_numref(RT(SELF)), mpq_denref(RT(SELF)));
mpq_canonicalize(RT(SELF));
#else
@@ -464,7 +460,6 @@ Returns the version of GNU Multiple Precision library. Returns 0.0.0, if GMP is
*/
VTABLE void decrement() {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpz_sub(mpq_numref(RT(SELF)), mpq_numref(RT(SELF)), mpq_denref(RT(SELF)));
mpq_canonicalize(RT(SELF));
#else
@@ -483,13 +478,13 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI PMC *add(Integer value, PMC* dest) {
dest = STATICSELF.clone();
- rat_add_integer(dest, VTABLE_get_integer(INTERP, value));
+ rat_add_integer(INTERP, dest, VTABLE_get_integer(INTERP, value));
return dest;
}
MULTI PMC *add(Float value, PMC* dest) {
dest = STATICSELF.clone();
- rat_add_float(dest, VTABLE_get_number(INTERP, value));
+ rat_add_float(INTERP, dest, VTABLE_get_number(INTERP, value));
return dest;
}
@@ -517,11 +512,11 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI void i_add(Integer value) {
- rat_add_integer(SELF, (int) VTABLE_get_integer(INTERP, value));
+ rat_add_integer(INTERP, SELF, (int) VTABLE_get_integer(INTERP, value));
}
MULTI void i_add(Float value) {
- rat_add_float(SELF, (double) VTABLE_get_number(INTERP, value));
+ rat_add_float(INTERP, SELF, (double) VTABLE_get_number(INTERP, value));
}
MULTI void i_add(Rational value) {
@@ -546,7 +541,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *add_int(INTVAL value, PMC* dest) {
dest = STATICSELF.clone();
- rat_add_integer(dest, (int) value);
+ rat_add_integer(INTERP, dest, (int) value);
return dest;
}
@@ -558,7 +553,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_add_int(INTVAL value) {
- rat_add_integer(SELF, (int) value);
+ rat_add_integer(INTERP, SELF, (int) value);
}
/*
@@ -570,7 +565,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *add_float(FLOATVAL value, PMC* dest) {
dest = STATICSELF.clone();
- rat_add_float(dest, (double) value);
+ rat_add_float(INTERP, dest, (double) value);
return dest;
}
@@ -582,8 +577,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_add_float(FLOATVAL value) {
- UNUSED(INTERP)
- rat_add_float(SELF, (double) value);
+ rat_add_float(INTERP, SELF, (double) value);
}
/*
@@ -595,13 +589,13 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI PMC *subtract(Integer value, PMC* dest) {
dest = STATICSELF.clone();
- rat_add_integer(dest, -((int) VTABLE_get_integer(INTERP, value)));
+ rat_add_integer(INTERP, dest, -((int) VTABLE_get_integer(INTERP, value)));
return dest;
}
MULTI PMC *subtract(Float value, PMC* dest) {
dest = STATICSELF.clone();
- rat_add_float(dest, - ((double) VTABLE_get_number(INTERP, value)));
+ rat_add_float(INTERP, dest, - ((double) VTABLE_get_number(INTERP, value)));
return dest;
}
@@ -628,18 +622,15 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI void i_subtract(Integer value) {
- UNUSED(INTERP)
- rat_add_integer(SELF, -((int) VTABLE_get_integer(INTERP, value)));
+ rat_add_integer(INTERP, SELF, -((int) VTABLE_get_integer(INTERP, value)));
}
MULTI void i_subtract(Float value) {
- UNUSED(INTERP)
- rat_add_float(SELF, - ((double) VTABLE_get_number(INTERP, value)));
+ rat_add_float(INTERP, SELF, - ((double) VTABLE_get_number(INTERP, value)));
}
MULTI void i_subtract(Rational value) {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpq_sub(RT(SELF), RT(SELF), RT(value));
#else
RAISE_EXCEPTION
@@ -659,9 +650,8 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *subtract_int(INTVAL value, PMC* dest) {
- UNUSED(INTERP)
dest = STATICSELF.clone();
- rat_add_integer(dest, -((int) value));
+ rat_add_integer(INTERP, dest, -((int) value));
return dest;
}
@@ -673,8 +663,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_subtract_int(INTVAL value) {
- UNUSED(INTERP)
- rat_add_integer(SELF, -((int) value));
+ rat_add_integer(INTERP, SELF, -((int) value));
}
/*
@@ -685,9 +674,8 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *subtract_float(FLOATVAL value, PMC* dest) {
- UNUSED(INTERP)
dest = STATICSELF.clone();
- rat_add_float(dest, -((double) value));
+ rat_add_float(INTERP, dest, -((double) value));
return dest;
}
@@ -699,8 +687,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_subtract_float(FLOATVAL value) {
- UNUSED(INTERP)
- rat_add_float(SELF, -((double) value));
+ rat_add_float(INTERP, SELF, -((double) value));
}
/*
@@ -712,13 +699,13 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI PMC *multiply(Integer value, PMC* dest) {
dest = STATICSELF.clone();
- rat_multiply_integer(dest, (int) VTABLE_get_integer(INTERP, value));
+ rat_multiply_integer(INTERP, dest, (int) VTABLE_get_integer(INTERP, value));
return dest;
}
MULTI PMC *multiply(Float value, PMC* dest) {
dest = STATICSELF.clone();
- rat_multiply_float(dest, (double) VTABLE_get_number(INTERP, value));
+ rat_multiply_float(INTERP, dest, (double) VTABLE_get_number(INTERP, value));
return dest;
}
@@ -745,11 +732,11 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI void i_multiply(Integer value) {
- rat_multiply_integer(SELF, (int) VTABLE_get_integer(INTERP, value));
+ rat_multiply_integer(INTERP, SELF, (int) VTABLE_get_integer(INTERP, value));
}
MULTI void i_multiply(Float value) {
- rat_multiply_float(SELF, (double) VTABLE_get_number(INTERP, value));
+ rat_multiply_float(INTERP, SELF, (double) VTABLE_get_number(INTERP, value));
}
MULTI void i_multiply(Rational value) {
@@ -773,9 +760,8 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *multiply_int(INTVAL value, PMC* dest) {
- UNUSED(INTERP)
dest = STATICSELF.clone();
- rat_multiply_integer(dest, (int) value);
+ rat_multiply_integer(INTERP, dest, (int) value);
return dest;
}
@@ -787,8 +773,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_multiply_int(INTVAL value) {
- UNUSED(INTERP)
- rat_multiply_integer(SELF, (int) value);
+ rat_multiply_integer(INTERP, SELF, (int) value);
}
/*
@@ -799,9 +784,8 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *multiply_float(FLOATVAL value, PMC* dest) {
- UNUSED(INTERP)
dest = STATICSELF.clone();
- rat_multiply_float(dest, (double) value);
+ rat_multiply_float(INTERP, dest, (double) value);
return dest;
}
@@ -813,8 +797,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_multiply_float(FLOATVAL value) {
- UNUSED(INTERP)
- rat_multiply_float(SELF, (double) value);
+ rat_multiply_float(INTERP, SELF, (double) value);
}
/*
@@ -826,13 +809,13 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI PMC *divide(Integer value, PMC* dest) {
dest = STATICSELF.clone();
- rat_divide_integer(dest, (int) VTABLE_get_integer(INTERP, value));
+ rat_divide_integer(INTERP, dest, (int) VTABLE_get_integer(INTERP, value));
return dest;
}
MULTI PMC *divide(Float value, PMC* dest) {
dest = STATICSELF.clone();
- rat_divide_float(dest, (double) VTABLE_get_number(INTERP, value));
+ rat_divide_float(INTERP, dest, (double) VTABLE_get_number(INTERP, value));
return dest;
}
@@ -859,18 +842,15 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI void i_divide(Integer value) {
- UNUSED(INTERP)
- rat_divide_integer(SELF, (int) VTABLE_get_integer(INTERP, value));
+ rat_divide_integer(INTERP, SELF, (int) VTABLE_get_integer(INTERP, value));
}
MULTI void i_divide(Float value) {
- UNUSED(INTERP)
- rat_divide_float(SELF, (double) VTABLE_get_number(INTERP, value));
+ rat_divide_float(INTERP, SELF, (double) VTABLE_get_number(INTERP, value));
}
MULTI void i_divide(Rational value) {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpq_div(RT(SELF), RT(SELF), RT(value));
#else
RAISE_EXCEPTION
@@ -891,7 +871,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *divide_int(INTVAL value, PMC* dest) {
dest = STATICSELF.clone();
- rat_divide_integer(dest, (int) value);
+ rat_divide_integer(INTERP, dest, (int) value);
return dest;
}
@@ -903,8 +883,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_divide_int(INTVAL value) {
- UNUSED(INTERP)
- rat_divide_integer(SELF, (int) value);
+ rat_divide_integer(INTERP, SELF, (int) value);
}
/*
@@ -915,9 +894,8 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE PMC *divide_float(FLOATVAL value, PMC* dest) {
- UNUSED(INTERP)
dest = STATICSELF.clone();
- rat_divide_float(dest, (double) value);
+ rat_divide_float(INTERP, dest, (double) value);
return dest;
}
@@ -929,8 +907,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_divide_float(FLOATVAL value) {
- UNUSED(INTERP)
- rat_divide_float(SELF, (double) value);
+ rat_divide_float(INTERP, SELF, (double) value);
}
/*
@@ -960,7 +937,6 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_neg() {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpq_neg(RT(SELF), RT(SELF));
#else
RAISE_EXCEPTION
@@ -994,7 +970,6 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
VTABLE void i_absolute() {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
mpq_abs(RT(SELF), RT(SELF));
#else
RAISE_EXCEPTION
@@ -1027,7 +1002,6 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
MULTI INTVAL cmp(Rational value) {
#ifdef PARROT_HAS_GMP
- UNUSED(INTERP)
return (INTVAL) mpq_cmp(RT(SELF), RT(value));
#else
RAISE_EXCEPTION
@@ -1048,7 +1022,7 @@ Adds Integer-, Float- or Rational-PMCs to SELF and stores them in dest.
*/
MULTI INTVAL is_equal(Integer value) {
#ifdef PARROT_HAS_GMP
- INTVAL eq;
+ INTVAL eq = 0;
mpq_t t;
mpq_init(t);
mpq_set_ui(t, VTABLE_get_integer(INTERP, value), 1);
Please sign in to comment.
Something went wrong with that request. Please try again.