mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-bigint: add fast path to mrb_bint_mul() & mrb_bint_div()
This commit is contained in:
@@ -1327,6 +1327,10 @@ mrb_bint_sub(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
mrb_value
|
||||
mrb_bint_mul(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
{
|
||||
if (mrb_integer_p(y)) {
|
||||
if (mrb_integer(y) == 0) return mrb_fixnum_value(0);
|
||||
if (mrb_integer(y) == 1) return bint_norm(mrb, RBIGINT(x));
|
||||
}
|
||||
#ifndef MRB_NO_FLOAT
|
||||
if (mrb_float_p(y)) {
|
||||
mrb_float v1 = mrb_bint_as_float(mrb, x);
|
||||
@@ -1345,6 +1349,10 @@ mrb_bint_mul(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
mrb_value
|
||||
mrb_bint_div(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
{
|
||||
if (mrb_integer_p(y)) {
|
||||
if (mrb_integer(y) == 0) mrb_int_zerodiv(mrb);
|
||||
if (mrb_integer(y) == 1) return bint_norm(mrb, RBIGINT(x));
|
||||
}
|
||||
#ifndef MRB_NO_FLOAT
|
||||
if (mrb_float_p(y)) {
|
||||
mrb_float v1 = mrb_bint_as_float(mrb, x);
|
||||
@@ -1352,9 +1360,6 @@ mrb_bint_div(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
return mrb_float_value(mrb,v1*v2);
|
||||
}
|
||||
#endif
|
||||
if (mrb_integer_p(y) && mrb_integer(y) == 0) {
|
||||
mrb_int_zerodiv(mrb);
|
||||
}
|
||||
y = mrb_as_bint(mrb, y);
|
||||
struct RBigint *b = RBIGINT(x);
|
||||
struct RBigint *b2 = RBIGINT(y);
|
||||
|
||||
Reference in New Issue
Block a user