[前][次][番号順一覧][スレッド一覧]

ruby-changes:4732

From: ko1@a...
Date: Mon, 28 Apr 2008 14:25:19 +0900 (JST)
Subject: [ruby-changes:4732] akr - Ruby:r16226 (trunk): * include/ruby/ruby.h (POSFIXABLE): use FIXNUM_MAX+1 instead of

akr	2008-04-28 14:25:03 +0900 (Mon, 28 Apr 2008)

  New Revision: 16226

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/ruby.h
    trunk/test/ruby/test_float.rb

  Log:
    * include/ruby/ruby.h (POSFIXABLE): use FIXNUM_MAX+1 instead of
      FIXNUM_MAX to make it possible to convert to double accurately.
      It assumes FLT_RADIX is 2.
      fix RubyForge bug #14102.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/ruby.h?r1=16226&r2=16225&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16226&r2=16225&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_float.rb?r1=16226&r2=16225&diff_format=u

Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 16225)
+++ include/ruby/ruby.h	(revision 16226)
@@ -193,7 +193,7 @@
 #define FIX2LONG(x) RSHIFT((SIGNED_VALUE)x,1)
 #define FIX2ULONG(x) ((((VALUE)(x))>>1)&LONG_MAX)
 #define FIXNUM_P(f) (((SIGNED_VALUE)(f))&FIXNUM_FLAG)
-#define POSFIXABLE(f) ((f) <= FIXNUM_MAX)
+#define POSFIXABLE(f) ((f) < FIXNUM_MAX+1)
 #define NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
 #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16225)
+++ ChangeLog	(revision 16226)
@@ -1,3 +1,10 @@
+Mon Apr 28 14:21:18 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/ruby.h (POSFIXABLE): use FIXNUM_MAX+1 instead of
+	  FIXNUM_MAX to make it possible to convert to double accurately.
+	  It assumes FLT_RADIX is 2.
+	  fix RubyForge bug #14102.
+
 Mon Apr 28 12:48:57 2008  NAKAMURA Usaku  <usa@r...>
 
 	* process.c (rb_exec_arg_addopt, rb_exec_arg_addopt): now can specify
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 16225)
+++ test/ruby/test_float.rb	(revision 16226)
@@ -277,4 +277,38 @@
     assert_equal(1.0, Float.induced_from(1.0))
     assert_raise(TypeError) { Float.induced_from(nil) }
   end
+
+  def test_to_i
+    assert_operator(4611686018427387905.0.to_i, :>, 0)
+    assert_operator(4611686018427387904.0.to_i, :>, 0)
+    assert_operator(4611686018427387903.8.to_i, :>, 0)
+    assert_operator(4611686018427387903.5.to_i, :>, 0)
+    assert_operator(4611686018427387903.2.to_i, :>, 0)
+    assert_operator(4611686018427387903.0.to_i, :>, 0)
+    assert_operator(4611686018427387902.0.to_i, :>, 0)
+
+    assert_operator(1073741825.0.to_i, :>, 0)
+    assert_operator(1073741824.0.to_i, :>, 0)
+    assert_operator(1073741823.8.to_i, :>, 0)
+    assert_operator(1073741823.5.to_i, :>, 0)
+    assert_operator(1073741823.2.to_i, :>, 0)
+    assert_operator(1073741823.0.to_i, :>, 0)
+    assert_operator(1073741822.0.to_i, :>, 0)
+
+    assert_operator((-1073741823.0).to_i, :<, 0)
+    assert_operator((-1073741824.0).to_i, :<, 0)
+    assert_operator((-1073741824.2).to_i, :<, 0)
+    assert_operator((-1073741824.5).to_i, :<, 0)
+    assert_operator((-1073741824.8).to_i, :<, 0)
+    assert_operator((-1073741825.0).to_i, :<, 0)
+    assert_operator((-1073741826.0).to_i, :<, 0)
+
+    assert_operator((-4611686018427387903.0).to_i, :<, 0)
+    assert_operator((-4611686018427387904.0).to_i, :<, 0)
+    assert_operator((-4611686018427387904.2).to_i, :<, 0)
+    assert_operator((-4611686018427387904.5).to_i, :<, 0)
+    assert_operator((-4611686018427387904.8).to_i, :<, 0)
+    assert_operator((-4611686018427387905.0).to_i, :<, 0)
+    assert_operator((-4611686018427387906.0).to_i, :<, 0)
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]