Branch: Tag:

2016-06-12

2016-06-12 12:47:18 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Gmp.mpz: Division of bignums with ints should now work again.

Also adds a testsuite test for division by negative integers.

FIXME: Division with negative integers that require rounding
is not tested as the rounding direction differs from
that of corresponding native integers.

1311:    float_promote++;    /* FIXME: should do rest of divisions with float as type.*/    } -  else if(TYPEOF(sp[e-args]) != T_INT || sp[e-args].u.integer<=0) +  else if(TYPEOF(sp[e-args]) == T_INT)    { -  if (!mpz_sgn(get_mpz(sp+e-args, 1, "`/", e + 1, args))) +  INT_TYPE i = sp[e-args].u.integer; +  if(!i) {    SIMPLE_DIVISION_BY_ZERO_ERROR ("`/"); -  if(TYPEOF(sp[e-args]) == T_INT) -  { +  } else { +  int negate = 0; +  if (i < 0) { +  i = -i; +  negate = 1; +  }   #ifdef BIG_PIKE_INT -  INT_TYPE i=sp[e-args].u.integer; -  if ( (unsigned long int)i == i) +  if ( (unsigned long int)i == (unsigned INT_TYPE)i)    { -  mpz_fdiv_q_ui(OBTOMPZ(res), OBTOMPZ(res), i); +  mpz_fdiv_q_ui(OBTOMPZ(res), OBTOMPZ(res), (unsigned long int)i);    }    else    {
1330: Inside #if defined(BIG_PIKE_INT)
  /* will this leak? there is no simple way of poking at the references to tmp */    }   #else -  mpz_fdiv_q_ui(OBTOMPZ(res), OBTOMPZ(res), sp[e-args].u.integer); +  mpz_fdiv_q_ui(OBTOMPZ(res), OBTOMPZ(res), i);   #endif -  +  if (negate) { +  mpz_neg(OBTOMPZ(res), OBTOMPZ(res));    } -  else +  } +  } +  else { +  if (!mpz_sgn(get_mpz(sp+e-args, 1, "`/", e + 1, args))) +  SIMPLE_DIVISION_BY_ZERO_ERROR ("`/"); +     mpz_fdiv_q(OBTOMPZ(res), OBTOMPZ(res), OBTOMPZ(sp[e-args].u.object));    }    }