Misc #10809 » add_test_about_overriding_Integer_to_f_20150222.patch
| test/ruby/test_math.rb | ||
|---|---|---|
|     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 | ||
| -  | ||
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »