示例#1
0
  void test_mul_with_bignum() {
    Fixnum*  one   = as<Fixnum>(Fixnum::from(2));
    Bignum* two   = Bignum::from(state, (native_int)FIXNUM_MAX + 10);
    Integer* three = one->mul(state, two);

    TS_ASSERT_EQUALS(three->class_object(state), G(bignum));
    Bignum* expected = as<Bignum>(two->mul(state, Fixnum::from(2)));

    TS_ASSERT_EQUALS(cTrue, as<Bignum>(three)->equal(state, expected));
  }
示例#2
0
  void test_mul_overflows_to_bignum() {
    Fixnum* half = Fixnum::from((FIXNUM_MAX + 1) / 2);
    Integer* max_plus1 = half->mul(state, Fixnum::from(2));

    TS_ASSERT(kind_of<Bignum>(max_plus1));
    TS_ASSERT_EQUALS(FIXNUM_MAX+1, max_plus1->to_native());

    Fixnum* neg_half = Fixnum::from((FIXNUM_MIN - 1) / 2);
    max_plus1 = neg_half->mul(state, Fixnum::from(-2));

    TS_ASSERT(kind_of<Bignum>(max_plus1));
    TS_ASSERT_EQUALS(FIXNUM_MAX+1, max_plus1->to_native());
  }
示例#3
0
  void test_mul() {
    Fixnum* third = Fixnum::from(FIXNUM_MAX / 3);
    Integer* a = third->mul(state, Fixnum::from(3));

    TS_ASSERT(kind_of<Fixnum>(a));
    TS_ASSERT_EQUALS(FIXNUM_MAX, a->to_native());

    Integer* min = third->mul(state, Fixnum::from(-3));

    TS_ASSERT(kind_of<Fixnum>(min));
    TS_ASSERT_EQUALS(FIXNUM_MIN + 1, min->to_native());

    Fixnum* neg_third = as<Fixnum>(Fixnum::from((FIXNUM_MIN))->div(state, Fixnum::from(3)));
    a = neg_third->mul(state, Fixnum::from(-3));

    TS_ASSERT(kind_of<Bignum>(a));
    TS_ASSERT_EQUALS(-FIXNUM_MIN + 2, a->to_native());

    a = neg_third->mul(state, Fixnum::from(3));

    TS_ASSERT(kind_of<Bignum>(a));
    TS_ASSERT_EQUALS(FIXNUM_MIN - 2, a->to_native());
  }
示例#4
0
  void test_mul_underflows_to_bignum() {
    Fixnum* half = Fixnum::from((FIXNUM_MAX + 1) / 2);
    Integer* min = half->mul(state, Fixnum::from(-2));

    TS_ASSERT(kind_of<Fixnum>(min));
    TS_ASSERT_EQUALS(FIXNUM_MIN, min->to_native());

    Integer* min_minus1 = Bignum::from(state, min->to_native())->sub(state, Fixnum::from(1));

    TS_ASSERT(kind_of<Bignum>(min_minus1));
    TS_ASSERT_EQUALS(FIXNUM_MIN - 1, min_minus1->to_native());

    Fixnum* neg_half = as<Fixnum>(Bignum::from(state, FIXNUM_MIN - 1)->div(state, Fixnum::from(2)));
    Integer* min_minus2 = neg_half->mul(state, Fixnum::from(2));

    TS_ASSERT(kind_of<Bignum>(min_minus2));
    TS_ASSERT_EQUALS(FIXNUM_MIN - 2, min_minus2->to_native());
  }
示例#5
0
 void test_mul_a_float() {
   Fixnum* one = Fixnum::from(13);
   Float* res = one->mul(state, Float::create(state, 1.4));
   check_float(res, Float::create(state, 18.2));
 }