本文整理汇总了C++中Fixnum::mul方法的典型用法代码示例。如果您正苦于以下问题:C++ Fixnum::mul方法的具体用法?C++ Fixnum::mul怎么用?C++ Fixnum::mul使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fixnum
的用法示例。
在下文中一共展示了Fixnum::mul方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_mul_with_bignum
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: test_mul_overflows_to_bignum
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: test_mul
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: test_mul_underflows_to_bignum
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: test_mul_a_float
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));
}