Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mruby/mruby
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Mar 16, 2014
2 parents 55c1942 + 0d82ada commit 3687e1f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;

x = mrb_float(self);
mrb_get_args(mrb, "f", &y);
mrb_value 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)
Expand Down
4 changes: 2 additions & 2 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def assertion_diff(exp, act)
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])
Expand Down
32 changes: 32 additions & 0 deletions test/t/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,43 @@
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
Expand Down
3 changes: 3 additions & 0 deletions test/t/float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

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
Expand Down
6 changes: 6 additions & 0 deletions test/t/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

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
Expand All @@ -31,6 +34,9 @@

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
Expand Down

0 comments on commit 3687e1f

Please sign in to comment.