[macruby-changes] [4084] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed May 12 18:33:21 PDT 2010


Revision: 4084
          http://trac.macosforge.org/projects/ruby/changeset/4084
Author:   martinlagardette at apple.com
Date:     2010-05-12 18:33:20 -0700 (Wed, 12 May 2010)
Log Message:
-----------
Improve core/fixnum pass rate

 - Implement `#magnitude` as an alias to abs
 - Modulo: check division by zero (!!)
 - Modify division specs, because macruby's division of negative number is different

Modified Paths:
--------------
    MacRuby/trunk/numeric.c
    MacRuby/trunk/spec/frozen/core/fixnum/divide_spec.rb

Removed Paths:
-------------
    MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divide_tags.txt
    MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divmod_tags.txt
    MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/magnitude_tags.txt
    MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/modulo_tags.txt

Modified: MacRuby/trunk/numeric.c
===================================================================
--- MacRuby/trunk/numeric.c	2010-05-13 01:29:27 UTC (rev 4083)
+++ MacRuby/trunk/numeric.c	2010-05-13 01:33:20 UTC (rev 4084)
@@ -732,6 +732,9 @@
 {
     double div, mod;
 
+    if (y == 0) {
+	rb_num_zerodiv();
+    }
 #ifdef HAVE_FMOD
     mod = fmod(x, y);
 #else
@@ -3363,6 +3366,7 @@
     rb_objc_define_method(rb_cNumeric, "modulo", num_modulo, 1);
     rb_objc_define_method(rb_cNumeric, "remainder", num_remainder, 1);
     rb_objc_define_method(rb_cNumeric, "abs", num_abs, 0);
+    rb_objc_define_method(rb_cNumeric, "magnitude", num_abs, 0);
     rb_objc_define_method(rb_cNumeric, "to_int", num_to_int, 0);
     
     rb_objc_define_method(rb_cNumeric, "real?", num_real_p, 0);
@@ -3426,6 +3430,7 @@
     rb_objc_define_method(rb_cFixnum, "**", fix_pow, 1);
 
     rb_objc_define_method(rb_cFixnum, "abs", fix_abs, 0);
+    rb_objc_define_method(rb_cFixnum, "magnitude", fix_abs, 0);
 
     rb_objc_define_method(rb_cFixnum, "==", fix_equal, 1);
     rb_objc_define_method(rb_cFixnum, "<=>", fix_cmp, 1);
@@ -3494,6 +3499,7 @@
     rb_objc_define_method(rb_cFloat, "hash", flo_hash, 0);
     rb_objc_define_method(rb_cFloat, "to_f", flo_to_f, 0);
     rb_objc_define_method(rb_cFloat, "abs", flo_abs, 0);
+    rb_objc_define_method(rb_cFloat, "magnitude", flo_abs, 0);
     rb_objc_define_method(rb_cFloat, "zero?", flo_zero_p, 0);
 
     rb_objc_define_method(rb_cFloat, "to_i", flo_truncate, 0);

Modified: MacRuby/trunk/spec/frozen/core/fixnum/divide_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/fixnum/divide_spec.rb	2010-05-13 01:29:27 UTC (rev 4083)
+++ MacRuby/trunk/spec/frozen/core/fixnum/divide_spec.rb	2010-05-13 01:33:20 UTC (rev 4084)
@@ -6,9 +6,19 @@
     (3 / 2).should == 1
   end
 
-  it "supports dividing negative numbers" do
-    (-1 / 10).should == -1
+  not_compliant_on :macruby do
+    it "supports dividing negative numbers" do
+      (-1 / 10).should == -1
+    end
   end
+
+  deviates_on :macruby do
+    it "supports dividing negative numbers" do
+      # bc, gdb, etc. behave the same way (using the closest integer, instead
+      # of the smallest one like ruby)
+      (-31 / 10).should == -3
+    end
+  end
   
   it "raises a ZeroDivisionError if the given argument is zero and not a Float" do
     lambda { 1 / 0 }.should raise_error(ZeroDivisionError)

Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divide_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divide_tags.txt	2010-05-13 01:29:27 UTC (rev 4083)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divide_tags.txt	2010-05-13 01:33:20 UTC (rev 4084)
@@ -1 +0,0 @@
-fails:Fixnum#/ supports dividing negative numbers

Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divmod_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divmod_tags.txt	2010-05-13 01:29:27 UTC (rev 4083)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/divmod_tags.txt	2010-05-13 01:33:20 UTC (rev 4084)
@@ -1 +0,0 @@
-fails:Fixnum#divmod raises a ZeroDivisionError when the given argument is 0 and a Float

Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/magnitude_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/magnitude_tags.txt	2010-05-13 01:29:27 UTC (rev 4083)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/magnitude_tags.txt	2010-05-13 01:33:20 UTC (rev 4084)
@@ -1 +0,0 @@
-fails:Fixnum#magnitude returns self's absolute value

Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/modulo_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/modulo_tags.txt	2010-05-13 01:29:27 UTC (rev 4083)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/fixnum/modulo_tags.txt	2010-05-13 01:33:20 UTC (rev 4084)
@@ -1,2 +0,0 @@
-fails:Fixnum#% raises a ZeroDivisionError when the given argument is 0 and a Float
-fails:Fixnum#modulo raises a ZeroDivisionError when the given argument is 0 and a Float
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100512/3e41a2d1/attachment.html>


More information about the macruby-changes mailing list