mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
numeric_ext.c: modulo and remainder should handle infinite argument.
This commit is contained in:
@@ -83,6 +83,7 @@ int_remainder(mrb_state *mrb, mrb_value x)
|
||||
mrb_float n = (mrb_float)a;
|
||||
mrb_float m = mrb_as_float(mrb, y);
|
||||
|
||||
if (isinf(m)) return mrb_float_value(mrb, n);
|
||||
return mrb_float_value(mrb, n-m*trunc(n/m));
|
||||
}
|
||||
#endif
|
||||
@@ -97,6 +98,7 @@ flo_remainder(mrb_state *mrb, mrb_value self)
|
||||
a = mrb_float(self);
|
||||
mrb_get_args(mrb, "f", &b);
|
||||
if (b == 0) zerodiv(mrb);
|
||||
if (isinf(b)) return mrb_float_value(mrb, a);
|
||||
return mrb_float_value(mrb, a-b*trunc(a/b));
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user