Feature #10909
closed
[PATCH 2/2] math.c: Direct casting from Rational to double.
Added by gogotanaka (Kazuki Tanaka) over 9 years ago.
Updated over 9 years ago.
Description
Hi, this proposal is continued from Feature 10800 and Feature 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
I can find this proposal makes Math
faster more than 2 times at most.
$ cat bench.rb
require 'benchmark'
puts Benchmark.measure { 10_000_000.times { Math.cos 1 } }
puts Benchmark.measure { 10_000_000.times { Math.cos 1 << 100 } }
puts Benchmark.measure { 10_000_000.times { Math.cos 1.0 } }
puts Benchmark.measure { 10_000_000.times { Math.cos 1/3r } }
puts Benchmark.measure { 10_000_000.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)
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r49818.
- math.c (num2dbl_with_to_f): direct casting from Rational to double.
[Feature #10909]
Also available in: Atom
PDF
Like0
Like0Like0