mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'master' of github.com:mruby/mruby
This commit is contained in:
+7
-8
@@ -690,10 +690,10 @@ mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
mrb_int a;
|
||||
|
||||
a = mrb_fixnum(x);
|
||||
if (a == 0) return x;
|
||||
if (mrb_fixnum_p(y)) {
|
||||
mrb_int b, c;
|
||||
|
||||
if (a == 0) return x;
|
||||
b = mrb_fixnum(y);
|
||||
if (FIT_SQRT_INT(a) && FIT_SQRT_INT(b))
|
||||
return mrb_fixnum_value(a*b);
|
||||
@@ -1131,10 +1131,10 @@ mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
|
||||
mrb_int a;
|
||||
|
||||
a = mrb_fixnum(x);
|
||||
if (a == 0) return y;
|
||||
if (mrb_fixnum_p(y)) {
|
||||
mrb_int b, c;
|
||||
|
||||
if (a == 0) return y;
|
||||
b = mrb_fixnum(y);
|
||||
c = a + b;
|
||||
if (((a < 0) ^ (b < 0)) == 0 && (a < 0) != (c < 0)) {
|
||||
@@ -1306,15 +1306,14 @@ num_cmp(mrb_state *mrb, mrb_value self)
|
||||
* and <code>other</code>.
|
||||
*/
|
||||
static mrb_value
|
||||
flo_plus(mrb_state *mrb, mrb_value self)
|
||||
flo_plus(mrb_state *mrb, mrb_value x)
|
||||
{
|
||||
mrb_float x, y;
|
||||
mrb_value y;
|
||||
|
||||
x = mrb_float(self);
|
||||
mrb_get_args(mrb, "f", &y);
|
||||
|
||||
return mrb_float_value(mrb, x + y);
|
||||
mrb_get_args(mrb, "o", &y);
|
||||
return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------*/
|
||||
void
|
||||
mrb_init_numeric(mrb_state *mrb)
|
||||
|
||||
+2
-2
@@ -338,7 +338,7 @@ mrb_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char
|
||||
mrb_value v;
|
||||
|
||||
if (mrb_type(val) == type) return val;
|
||||
v = convert_type(mrb, val, tname, method, 1/*Qtrue*/);
|
||||
v = convert_type(mrb, val, tname, method, TRUE);
|
||||
if (mrb_type(v) != type) {
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "%S cannot be converted to %S by #%S", val,
|
||||
mrb_str_new_cstr(mrb, tname), mrb_str_new_cstr(mrb, method));
|
||||
@@ -352,7 +352,7 @@ mrb_check_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const
|
||||
mrb_value v;
|
||||
|
||||
if (mrb_type(val) == type && type != MRB_TT_DATA) return val;
|
||||
v = convert_type(mrb, val, tname, method, 0/*Qfalse*/);
|
||||
v = convert_type(mrb, val, tname, method, FALSE);
|
||||
if (mrb_nil_p(v) || mrb_type(v) != type) return mrb_nil_value();
|
||||
return v;
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ end
|
||||
def assert_true(ret, msg = nil, diff = nil)
|
||||
if $mrbtest_assert
|
||||
$mrbtest_assert_idx += 1
|
||||
if !ret
|
||||
unless ret
|
||||
msg = "Expected #{ret.inspect} to be true" unless msg
|
||||
diff = assertion_diff(true, ret) unless diff
|
||||
$mrbtest_assert.push([$mrbtest_assert_idx, msg, diff])
|
||||
|
||||
@@ -8,11 +8,43 @@ end
|
||||
assert('Enumerable#all?', '15.3.2.2.1') do
|
||||
assert_true([1,2,3].all?)
|
||||
assert_false([1,false,3].all?)
|
||||
|
||||
a = [2,4,6]
|
||||
all = a.all? do |e|
|
||||
if e % 2 == 0
|
||||
true
|
||||
end
|
||||
end
|
||||
assert_true(all)
|
||||
|
||||
a = [2,4,7]
|
||||
all = a.all? do |e|
|
||||
if e % 2 == 0
|
||||
true
|
||||
end
|
||||
end
|
||||
assert_false(all)
|
||||
end
|
||||
|
||||
assert('Enumerable#any?', '15.3.2.2.2') do
|
||||
assert_true([false,true,false].any?)
|
||||
assert_false([false,false,false].any?)
|
||||
|
||||
a = [1,3,6]
|
||||
any = a.any? do |e|
|
||||
if e % 2 == 0
|
||||
true
|
||||
end
|
||||
end
|
||||
assert_true(any)
|
||||
|
||||
a = [1,3,5]
|
||||
any = a.any? do |e|
|
||||
if e % 2 == 0
|
||||
true
|
||||
end
|
||||
end
|
||||
assert_false(any)
|
||||
end
|
||||
|
||||
assert('Enumerable#collect', '15.3.2.2.3') do
|
||||
|
||||
@@ -15,6 +15,9 @@ assert('Float#+', '15.2.9.3.1') do
|
||||
|
||||
assert_float(3.123456789, a)
|
||||
assert_float(4.123456789, b)
|
||||
|
||||
assert_raise(TypeError){ 0.0+nil }
|
||||
assert_raise(TypeError){ 1.0+nil }
|
||||
end
|
||||
|
||||
assert('Float#-', '15.2.9.3.2') do
|
||||
|
||||
@@ -15,6 +15,9 @@ assert('Integer#+', '15.2.8.3.1') do
|
||||
|
||||
assert_equal 2, a
|
||||
assert_equal 2.0, b
|
||||
|
||||
assert_raise(TypeError){ 0+nil }
|
||||
assert_raise(TypeError){ 1+nil }
|
||||
end
|
||||
|
||||
assert('Integer#-', '15.2.8.3.2') do
|
||||
@@ -31,6 +34,9 @@ assert('Integer#*', '15.2.8.3.3') do
|
||||
|
||||
assert_equal 1, a
|
||||
assert_equal 1.0, b
|
||||
|
||||
assert_raise(TypeError){ 0*nil }
|
||||
assert_raise(TypeError){ 1*nil }
|
||||
end
|
||||
|
||||
assert('Integer#/', '15.2.8.3.4') do
|
||||
|
||||
Reference in New Issue
Block a user