From: mail@... Date: 2015-02-26T12:59:17+00:00 Subject: [ruby-core:68326] [Ruby trunk - Feature #10909] [PATCH 2/2] math.c: Direct casting from Rational to double. Issue #10909 has been updated by gogo tanaka. I can find this proposal makes `Math` faster more than 2 times at most. $ cat bench.rb ```ruby require 'benchmark' puts Benchmark.measure { 10000000.times { Math.cos 1 } } puts Benchmark.measure { 10000000.times { Math.cos (1 << 100) } } puts Benchmark.measure { 10000000.times { Math.cos 1.0 } } puts Benchmark.measure { 10000000.times { Math.cos 1/3r } } puts Benchmark.measure { 10000000.times { Math.cos (1 << 100)/1r } } ``` ### Before ``` 1.320000 0.010000 1.330000 ( 1.326548) 3.060000 0.000000 3.060000 ( 3.064614) 1.380000 0.000000 1.380000 ( 1.383077) 5.360000 0.010000 5.370000 ( 5.435371) 19.220000 0.050000 19.270000 ( 19.565904) ``` ### After ``` 1.350000 0.000000 1.350000 ( 1.357702) 3.230000 0.010000 3.240000 ( 3.247377) 1.310000 0.000000 1.310000 ( 1.315977) 2.100000 0.000000 2.100000 ( 2.106907) 15.590000 0.040000 15.630000 ( 15.898346) ``` ---------------------------------------- Feature #10909: [PATCH 2/2] math.c: Direct casting from Rational to double. https://bugs.ruby-lang.org/issues/10909#change-51677 * Author: gogo tanaka * Status: Open * Priority: Normal * Assignee: ---------------------------------------- Hi, this proposal is continued from [Feature 10800](https://bugs.ruby-lang.org/issues/10800) and [Feature 10785](https://bugs.ruby-lang.org/issues/10785) I'd like to do cast from Rational to double unless Rational#to_f is redefined. Along with that, I've introduced some new macros(`fix2dbl_without_to_f`, `big2dbl_without_to_f`, ..) and added test cases. Please feel free to let me know if there are something you don't like. thanks. ---Files-------------------------------- direct_casting_from_Rational_to_double.patch (1.45 KB) add_tests_to_test_math_rb.patch (1.79 KB) -- https://bugs.ruby-lang.org/