Esempio n. 1
0
RCP<const Number> Complex::powcomp(const Integer &other) const {
    if (this->is_re_zero()) {
        // Imaginary Number raised to an integer power.
        RCP<const Number> im = Rational::from_mpq(this->imaginary_);
        long rem = mod(other, *integer(4))->as_int();
        RCP<const Number> res;
        if (rem == 0) {
            res = one;
        } else if (rem == 1) {
            res = I;
        } else if (rem == 2) {
            res = minus_one;
        } else {
            res = mulnum(I, minus_one);
        }
        return mulnum(im->pow(other), res);
    } else if (other.is_positive()) {
        return pow_number(*this, other.as_int());
    } else {
        return one->div(*pow_number(*this, -1 * other.as_int()));
    }
};
Esempio n. 2
0
TESTF(ByteArrayPrimsTests, alienAddressShouldReturnLargeIntegerAddress) {
  u_char* bytes = alien->bytes();

  int address = -128 * 256 * 256 * 256;
  ((int*)bytes)[0] = 0;
  ((u_char**)bytes)[1] = (u_char*) address;
  oop result = byteArrayPrimitives::alienGetAddress(alien);
  ASSERT_TRUE_M(result->is_byteArray(), "should be large integer");

  Integer* number = &byteArrayOop(result)->number();
  bool ok;
  int resultAddress = number->as_int(ok);
  ASSERT_TRUE_M(ok, "too large for int");
  ASSERT_EQUALS_M(address, resultAddress, "wrong address");
}
Esempio n. 3
0
 int asInteger(oop largeInteger, bool& ok) {
   Integer* number = &byteArrayOop(largeInteger)->number();
   return number->as_int(ok);
 }