From afe24d819c535f850bb12f65577fd911fd20bafc Mon Sep 17 00:00:00 2001 From: gogotanaka Date: Sun, 22 Feb 2015 09:56:18 +0900 Subject: [PATCH 1/1] add_test_for_math_c_about_overriding_Integer_to_f.patch To: https://bugs.ruby-lang.org/ --- test/ruby/test_math.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/ruby/test_math.rb b/test/ruby/test_math.rb index c4d0ff9..4d975b6 100644 --- a/test/ruby/test_math.rb +++ b/test/ruby/test_math.rb @@ -289,4 +289,33 @@ class TestMath < Test::Unit::TestCase check(3, Math.cbrt(27)) check(-0.1, Math.cbrt(-0.001)) end + + def test_override_fixnum_to_f + Fixnum.class_eval do + alias _to_f to_f + def to_f + (self + 1)._to_f + end + end + + check(Math.cos((0 + 1)._to_f), Math.cos(0)) + check(Math.exp((0 + 1)._to_f), Math.exp(0)) + check(Math.log((0 + 1)._to_f), Math.log(0)) + + Fixnum.class_eval { alias to_f _to_f } + end + + def test_override_bignum_to_f + Bignum.class_eval do + alias _to_f to_f + def to_f + (self << 1)._to_f + end + end + + check(Math.cos((1 << 62 << 1)._to_f), Math.cos(1 << 62)) + check(Math.log((1 << 62 << 1)._to_f), Math.log(1 << 62)) + + Bignum.class_eval { alias to_f _to_f } + end end -- gogotanaka