本文整理汇总了C++中Fixnum::divmod方法的典型用法代码示例。如果您正苦于以下问题:C++ Fixnum::divmod方法的具体用法?C++ Fixnum::divmod怎么用?C++ Fixnum::divmod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fixnum
的用法示例。
在下文中一共展示了Fixnum::divmod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_divmod
void test_divmod() {
Fixnum* one = as<Fixnum>(Fixnum::from(15));
Fixnum* two = as<Fixnum>(Fixnum::from(4));
Array* ary1 = one->divmod(state, two);
Object* o1 = ary1->get(state, 0);
Object* o2 = ary1->get(state, 1);
TS_ASSERT(o1->fixnum_p());
TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), 3);
TS_ASSERT(o2->fixnum_p());
TS_ASSERT_EQUALS(as<Integer>(o2)->to_native(), 3);
Fixnum* zero = Fixnum::from(0);
TS_ASSERT_THROWS_ASSERT(one->divmod(state, zero), const RubyException &e,
TS_ASSERT(Exception::zero_division_error_p(state, e.exception)));
}
示例2: test_divmod_with_a_float
void test_divmod_with_a_float() {
Fixnum* one = as<Fixnum>(Fixnum::from(15));
Array* ary1 = one->divmod(state, Float::create(state, -3.3));
Object* o1 = ary1->get(state, 0);
Object* o2 = ary1->get(state, 1);
TS_ASSERT(o1->fixnum_p());
TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), -5);
check_float(as<Float>(o2), Float::create(state, -1.5));
}
示例3: test_divmod_with_a_bignum
void test_divmod_with_a_bignum() {
Fixnum* one = as<Fixnum>(Fixnum::from(15));
Bignum* two = Bignum::from(state, (native_int)4);
Array* ary1 = one->divmod(state, two);
Object* o1 = ary1->get(state, 0);
Object* o2 = ary1->get(state, 1);
TS_ASSERT(o1->fixnum_p());
TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), 3);
TS_ASSERT(o2->fixnum_p());
TS_ASSERT_EQUALS(as<Integer>(o2)->to_native(), 3);
}