diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-03 07:48:09 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-03 07:48:09 +0000 |
| commit | 356ecfc99e553607e33d2189f836c9a6beb9c810 (patch) | |
| tree | 78042dc17b6d83186c3cbe0716355b7996866601 | |
| parent | 0f67efee0e088862fd2bdedafd1c35fec109ada7 (diff) | |
* 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.
backported from 1.9.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | ruby.h | 2 | ||||
| -rw-r--r-- | test/ruby/test_float.rb | 34 |
3 files changed, 43 insertions, 1 deletions
@@ -1,3 +1,11 @@ +Thu Jul 3 16:46:56 2008 Tanaka Akira <akr@fsij.org> + + * 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. + backported from 1.9. + Thu Jul 3 16:08:36 2008 Tanaka Akira <akr@fsij.org> * configure.in (erfc): erfc of glibc comes with Debian GNU/Linux Etch @@ -166,7 +166,7 @@ VALUE rb_ull2inum _((unsigned LONG_LONG)); #define FIX2LONG(x) RSHIFT((long)x,1) #define FIX2ULONG(x) (((unsigned long)(x))>>1) #define FIXNUM_P(f) (((long)(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 d559ce5cab..cbc6a7886b 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -110,4 +110,38 @@ class TestFloat < Test::Unit::TestCase assert_equal(-3.5, (-11.5).remainder(4)) assert_equal(-3.5, (-11.5).remainder(-4)) 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 |
