aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
Commit message (Collapse)AuthorAgeFilesLines
* numeric.c: optimize `float ** 2` case by fastpathYusuke Endoh2020-05-121-1/+5
| | | | | | It would be a relatively frequent case. It is still slower than `float * float` because `*` has a dedicated VM instruction (opt_mult), though.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Added more NORETURN declarationsNobuyoshi Nakada2020-05-111-0/+2
|
* numeric.c: Remove unreachable codeYusuke Endoh2020-04-091-4/+1
| | | | b cannot be <= 0 here. Found by Coverity Scan
* Suppress C4244 "possible loss of data" warningsNobuyoshi Nakada2020-04-081-1/+1
|
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-4/+16
| | | Split ruby.h
* Removed non-RUBY_INTEGER_UNIFICATION codeNobuyoshi Nakada2020-03-211-6/+0
|
* Remove Float::ROUNDSJeremy Evans2020-03-091-20/+0
| | | | Fixes [Bug #16044]
* Check the encoding of `half:` optionNobuyoshi Nakada2020-01-271-0/+1
|
* decouple internal.h headers卜部昌平2019-12-261-4/+18
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* add several __has_something macro卜部昌平2019-12-261-11/+11
| | | | | | | With these macros implemented we can write codes just like we can assume the compiler being clang. MSC_VERSION_SINCE is defined to implement those macros, but turned out to be handy for other places. The -fdeclspec compiler flag is necessary for clang to properly handle __has_declspec().
* make functions static卜部昌平2019-11-191-3/+4
| | | | | | | These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
* Use FIX2LONG instead of FIX2INT like 26843cbcd0NARUSE, Yui2019-11-071-4/+4
|
* Use FIX2LONG to avoid unexpected exceptionNARUSE, Yui2019-11-071-1/+1
| | | | | Though it won't happen in the real world in this context, FIX2INT may raise an exception and it cause to generate extra code.
* Suppress keyword argument warning from #stepNobuyoshi Nakada2019-09-301-1/+1
| | | | | | * numeric.c (num_step): pass the extracted argument from keyword argument, not the last argument itself which should have been warned already.
* Inspect dynamic symbol as well as static symbolNobuyoshi Nakada2019-08-251-1/+1
|
* Expanded f_quoNobuyoshi Nakada2019-08-101-3/+3
|
* Deprecate Float::ROUNDS, which should not be a constantNobuyoshi Nakada2019-08-071-1/+4
| | | | [Bug #16044]
* Predefine some IDsNobuyoshi Nakada2019-08-031-7/+6
|
* Expanded f_ceilNobuyoshi Nakada2019-08-021-1/+8
|
* Adjust styles and indentsNobuyoshi Nakada2019-07-191-1/+2
|
* numeric.c (fix_cmp): remove a unreachable return statementYusuke Endoh2019-07-141-1/+0
|
* * expand tabs.git2019-07-141-1/+1
|
* Prefer `rb_error_arity` to `rb_check_arity` when it can be usedYusuke Endoh2019-07-141-2/+1
|
* Make opt_aref instruction support Integer#[]Yusuke Endoh2019-06-011-3/+3
| | | | | | | | | | | | only when its receiver and the argument are both Integers. Since 6bedbf4625, Integer#[] has supported a range extraction. This means that Integer#[] now accepts multiple arguments, which made the method very slow unfortunately. This change fixes the performance issue by adding a special handling for its traditional use case: `num[idx]` where both `num` and `idx` are Integers.
* Update broken URL in Float documentation.Hiroshi SHIBATA2019-05-041-1/+1
| | | | [Misc #15775][ruby-core:92332]
* * expand tabs.git2019-04-281-4/+4
|
* numeric.c: Extend Integer#[] to support range argumentsYusuke Endoh2019-04-281-23/+125
| | | | | | | | | | | ```` 0b01001101[2, 4] #=> 0b0011 0b01001100[2..5] #=> 0b0011 0b01001100[2...6] #=> 0b0011 ^^^^ ```` [Feature #8842]
* numeric.c: fix infinite loopnobu2019-03-111-0/+1
| | | | | | | | * numeric.c (int_pow): fix infinite loop in the case of y equal 1 and power of x does not overflow. [ruby-core:91734] [Bug #15651] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: fix arith_seq_first for Infinitymrkn2019-01-301-1/+1
| | | | | | | | | | | | | | * enumerator.c (arith_seq_first): fix for Float::INFINITY. * test/ruby/test_arithmetic_sequence.rb: add tests. * numeric.c (ruby_float_step_size): export for internal use. * internal.h: add prototype declaration of ruby_float_step_size. [ruby-core:90937][Bug #15518] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-01-241-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: Fix negative step with float componentsmrkn2019-01-241-2/+2
| | | | | | | | | | | | | | * numeric.c (ruby_float_step): fix negative step with float components. * test/ruby/test_numeric.c (test_step_bug15537): add tests. * test/ruby/test_range.c (test_step_bug15537): add tests. [Bug #15537] [ruby-core:91101] From: shuujii (Shuji KOBAYASHI) <shuujii@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: optimize zero check for Floatmrkn2019-01-091-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: Optimize Complex#* and Complex#**mrkn2019-01-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optimize f_mul for the core numeric class components. This change improves the computation time of Complex#* and Complex#**. ``` $ make benchmark ITEM=complex_float_ COMPARE_RUBY=/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby generating known_errors.inc known_errors.inc unchanged /Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged /Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \ --executables="compare-ruby::/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby -I.ext/common --disable-gem" \ --executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \ $(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*complex_float_*.yml' -o -name '*complex_float_*.rb' | sort) Calculating ------------------------------------- compare-ruby built-ruby complex_float_add 6.558M 13.012M i/s - 1.000M times in 0.152480s 0.076850s complex_float_div 576.821k 567.969k i/s - 1.000M times in 1.733640s 1.760660s complex_float_mul 1.690M 2.628M i/s - 1.000M times in 0.591786s 0.380579s complex_float_new 1.350M 1.268M i/s - 1.000M times in 0.740669s 0.788762s complex_float_power 1.571M 1.835M i/s - 1.000M times in 0.636507s 0.544909s complex_float_sub 8.635M 8.779M i/s - 1.000M times in 0.115814s 0.113906s Comparison: complex_float_add built-ruby: 13012361.7 i/s compare-ruby: 6558237.1 i/s - 1.98x slower complex_float_div compare-ruby: 576821.0 i/s built-ruby: 567968.8 i/s - 1.02x slower complex_float_mul built-ruby: 2627575.4 i/s compare-ruby: 1689800.0 i/s - 1.55x slower complex_float_new compare-ruby: 1350130.8 i/s built-ruby: 1267809.6 i/s - 1.06x slower complex_float_power built-ruby: 1835168.8 i/s compare-ruby: 1571074.6 i/s - 1.17x slower complex_float_sub built-ruby: 8779168.8 i/s compare-ruby: 8634534.7 i/s - 1.02x slower ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: Optimize Complex#+ for some conditionsmrkn2019-01-011-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optimize f_add defined in complex.c for some specific conditions. It makes Complex#+ about 1.4x faster than r66678. Compared to r66678: ``` mrkn-mbp15-late2016:complex-optim-o3 mrkn$ make benchmark ITEM=complex_float_ COMPARE_RUBY=/Users/mrkn/.rbenv/versions/trunk-o3/bin/ruby /Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged /Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \ --executables="compare-ruby::/Users/mrkn/.rbenv/versions/trunk-o3/bin/ruby -I.ext/common --disable-gem" \ --executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \ $(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*complex_float_*.yml' -o -name '*complex_float_*.rb' | sort) Calculating ------------------------------------- compare-ruby built-ruby complex_float_add 9.132M 12.864M i/s - 1.000M times in 0.109511s 0.077734s complex_float_div 600.723k 627.878k i/s - 1.000M times in 1.664662s 1.592666s complex_float_mul 2.320M 2.347M i/s - 1.000M times in 0.431039s 0.426113s complex_float_new 1.473M 1.489M i/s - 1.000M times in 0.678791s 0.671750s complex_float_power 1.690M 1.722M i/s - 1.000M times in 0.591863s 0.580775s complex_float_sub 8.870M 9.516M i/s - 1.000M times in 0.112740s 0.105091s Comparison: complex_float_add built-ruby: 12864383.7 i/s compare-ruby: 9131502.8 i/s - 1.41x slower complex_float_div built-ruby: 627878.0 i/s compare-ruby: 600722.5 i/s - 1.05x slower complex_float_mul built-ruby: 2346795.3 i/s compare-ruby: 2319975.7 i/s - 1.01x slower complex_float_new built-ruby: 1488649.1 i/s compare-ruby: 1473207.5 i/s - 1.01x slower complex_float_power built-ruby: 1721837.2 i/s compare-ruby: 1689580.2 i/s - 1.02x slower complex_float_sub built-ruby: 9515562.7 i/s compare-ruby: 8869966.3 i/s - 1.07x slower ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: rb_complex_new_polarnobu2018-12-121-2/+2
| | | | | | | | | * complex.c (rb_complex_new_polar): renamed with _new to clarify that it creates a new instance, but is not an instance method. * complex.c (rb_complex_polar): deprecated. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Make some internal functions staticnobu2018-11-161-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: avoid division by zeroshyouhei2018-11-161-1/+1
| | | | | | | Forgot to add in r65751. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* avoid division by zeroshyouhei2018-11-161-14/+12
| | | | | | | | | | | | | | * cvt(): use signbit() instead of 1/d < 0 * w_float(): ditto * ruby_float_step_size(): unit==0 check shall be prior to divisions * arith_seq_float_step_size(): ditto * rb_big_divide(): same as r65642 * fix_divide(): ditto * rb_big_fdiv_double(): ditto * fix_fdiv_double(): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Export rb_flo_div_flo for MJITnobu2018-11-121-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: fix typoshyouhei2018-11-121-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_insnhelper.c: avoid division by zeroshyouhei2018-11-121-34/+31
| | | | | | | same as r65642. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: avoid division by zeroshyouhei2018-11-091-11/+43
| | | | | | | | | | | | | | | | | | | In C, division by zero is undefined, even if the expression is double (cf: ISO/IEC 9899:1990 section 6.3.5). OTOH we have tests about such operations and results, means we expect no exceptional situation shall occur. We need to carefully reroute the situation, and generate what is needed. See also: https://travis-ci.org/ruby/ruby/jobs/452680646#L2943 PS: Recently (last two decades), C have Annex. F document. It normatively specifies that the division operator is IEEE 754's division operator (cf: ISO/IEC 9899:1999 section F.3). If we could move to such newer version this could be no problem. But that is not possible today. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: rb_dbl_complex_polar_pinobu2018-11-041-2/+2
| | | | | | | * complex.c (rb_dbl_complex_polar_pi): suffixed with _pi to clarify that `ang` is not radian, but multiplied by PI. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: small optimization of Complex#**nobu2018-10-201-0/+16
| | | | | | | | * complex.c (rb_complex_pow): calculate power of a Fixnum without allocating intermediate Complex objects, and avoid unexpected NaNs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix Rational of Floatnobu2018-10-021-4/+5
| | | | | | [ruby-core:89239] [Bug #15189] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2018-09-291-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: may be floatnobu2018-09-291-1/+7
| | | | | | | * rational.c (f_muldiv): Integer#** can return Rational with Float right now. [ruby-core:89212] [Bug #15175] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e