From 6daf55634550c612dc625f5093fc02b9b91f9f8b Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 28 Apr 2008 05:25:03 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ include/ruby/ruby.h | 2 +- test/ruby/test_float.rb | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f3c139b52f..17b3038f68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Apr 28 14:21:18 2008 Tanaka Akira + + * 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 * process.c (rb_exec_arg_addopt, rb_exec_arg_addopt): now can specify diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index e6ea830e64..da4c48f447 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -193,7 +193,7 @@ VALUE rb_ull2inum(unsigned LONG_LONG); #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)) diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 4fa549ce52..3b23a3cd82 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -277,4 +277,38 @@ class TestFloat < Test::Unit::TestCase 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