[svn:parrot] r39595 - in trunk: src/pmc t/pmc
Infinoid at svn.parrot.org
Infinoid at svn.parrot.org
Tue Jun 16 21:58:19 UTC 2009
Author: Infinoid
Date: Tue Jun 16 21:58:19 2009
New Revision: 39595
URL: https://trac.parrot.org/parrot/changeset/39595
Log:
[bignum] Fix bignum_div_bignum_float and test it.
Modified:
trunk/src/pmc/bignum.pmc
trunk/t/pmc/bignum.t
Modified: trunk/src/pmc/bignum.pmc
==============================================================================
--- trunk/src/pmc/bignum.pmc Tue Jun 16 21:58:11 2009 (r39594)
+++ trunk/src/pmc/bignum.pmc Tue Jun 16 21:58:19 2009 (r39595)
@@ -474,18 +474,22 @@
static void
bignum_div_bignum_float(PARROT_INTERP, PMC *self, FLOATVAL value, PMC *dest) {
- BIGNUM *bn, *bn_self, *bn_dest;
+ BIGNUM bn, *bn_self, *bn_dest;
GETATTR_BigNum_bn(interp, self, bn_self);
GETATTR_BigNum_bn(interp, dest, bn_dest);
int_check_divide_zero(interp, value);
+ mpf_init(bn.b);
if (value < 0) {
- mpf_set_d(bn->b, -value);
- mpf_div(bn_dest->b, bn_self->b, bn->b);
+ mpf_set_d(bn.b, -value);
+ mpf_div(bn_dest->b, bn_self->b, bn.b);
mpf_neg(bn_dest->b, bn_dest->b);
}
- else
- mpf_div(bn_dest->b, bn_self->b, bn->b);
+ else {
+ mpf_set_d(bn.b, value);
+ mpf_div(bn_dest->b, bn_self->b, bn.b);
+ }
+ mpf_clear(bn.b);
}
/* There's no such mpf_fdiv, only mpz_fdiv and mpf_div */
@@ -1350,6 +1354,13 @@
return dest;
}
+ VTABLE PMC *divide_float(FLOATVAL value, PMC *dest) {
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
+
+ bignum_div_bignum_float(INTERP, SELF, value, dest);
+ return dest;
+ }
+
MULTI void i_divide(BigNum value) {
bignum_div_bignum(INTERP, SELF, value, SELF);
}
Modified: trunk/t/pmc/bignum.t
==============================================================================
--- trunk/t/pmc/bignum.t Tue Jun 16 21:58:11 2009 (r39594)
+++ trunk/t/pmc/bignum.t Tue Jun 16 21:58:19 2009 (r39595)
@@ -25,7 +25,7 @@
=cut
if ( $PConfig{gmp} ) {
- plan tests => 32;
+ plan tests => 33;
}
else {
plan skip_all => "No BigNum PMC enabled";
@@ -385,6 +385,29 @@
ok 2
OUT
+pasm_output_is( <<'CODE', <<'OUT', "div float" );
+ new P0, ['BigNum']
+ set P0, "100000000000000000000"
+ new P1, ['BigNum']
+ div P1, P0, 10.0
+ new P2, ['BigNum']
+ set P2, "10000000000000000000"
+ eq P1, P2, OK1
+ print "not "
+OK1: say "ok 1"
+
+ set P0, "100000000000000"
+ div P1, P0, -10.0
+ set P2, "-10000000000000"
+ eq P1, P2, OK2
+ print "not "
+OK2: say "ok 2"
+ end
+CODE
+ok 1
+ok 2
+OUT
+
my @todo_sig = ( todo => "missing signature" );
for my $op ( "/", "%" ) {
for my $type ( "BigNum", "BigInt", "Integer" ) {
More information about the parrot-commits
mailing list