summaryrefslogtreecommitdiff
path: root/complex.c
AgeCommit message (Collapse)Author
2019-01-18merge revision(s) 66796,66797: [Backport #15525]naruse
No TypeError at nil if exception: false [ruby-core:91021] [Bug #15525] No FloatDomainError at non-finitive number if exception: false [ruby-core:91021] [Bug #15525] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-17merge revision(s) 66681,66682,66684,66688,66697,66751,66693,66694: [Backport ↵naruse
#15491] complex.c: Optimize Complex#+ for some conditions 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 ``` suppress warning: method redefined; discarding old + introduced at r66681 complex.c: fix indentation complex.c: fix against redefining component methods This fixes the incompatibility (maybe unintentionally) introduced by removal of `#ifndef PRESERVE_SIGNEDZERO` guards in f_add, f_mul, and f_sub functions in r62701. [Bug #15491] [ruby-core:90843] complex.c: Optimize Complex#* and Complex#** 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 ``` complex.c: replace misused UNLIKELY with LIKELY test_complex.rb: fix tests for RUBYOPT="-w" test_complex.rb: use the same approach to fix failures as r66682. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-24complex.c, object.c: [DOC] improve "exception: false" docsstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22{complex,object,rational}.c: document exception: falsenormal
From: Victor Shepelev <zverok.offline@gmail.com> [ruby-core:90673] [Bug #15452] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22Use idExceptionnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12complex.c: new APIs for Complexnobu
[Feature #15066] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12complex.c: rb_complex_new_polarnobu
* 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
2018-12-04Prefer rb_check_arity when 0 or 1 argumentsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04complex.c: rb_dbl_complex_polar_pinobu
* 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
2018-10-20* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20complex.c: small optimization of Complex#**nobu
* 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
2018-09-01complex.c: simplify division resultnobu
* complex.c (f_divide): canonicalize rationals to simplify integer complex results. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17share Float 0nobu
* complex.c (RFLOAT_0): share the 0.0 object on non-flonum platforms. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17refine Integer#** and Float#**nobu
* complex.c (rb_dbl_complex_polar): utility function, which returns more precise value in right angle cases. * bignum.c (rb_big_pow): use rb_dbl_complex_polar(). * numeric.c (rb_float_pow, fix_pow): create a Complex by polar form. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-14complex.c: improve docs for Complex#{finite?,infinite?}stomar
* complex.c: [DOC] correct term "real value" to "real part", and same for imaginary part, in documentation for Complex#{finite?,infinite?}. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-26Update Complex#infinite? documenationnobu
to state what it really does. [Fix GH-1848] From: Christian Bruckmayer <cbruckmayer@suse.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-26Update Complex#finite? documentationnobu
to state what it really does. [Fix GH-1848] From: Christian Bruckmayer <cbruckmayer@suse.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15Add `exception:` keyword in Kernel#Complex()mrkn
Support `exception:` keyword argument in `Kernel#Complex()`. If `exception:` is `false`, `Kernel#Complex()` returns `nil` if the given value cannot be interpreted as a complex value. The default value of `exception:` is `true`. This is part of [Feature #12732]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-09Removed useless assertions [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-09complex.c: removed redundant conditionsnobu
Fixnums can be compared by object values themselves only. Addition/subtraction/mulplication of fixnum 0 do not affect the sign. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-09complex.c: removed already unused macrosnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07complex.c: check typenobu
* complex.c (m_cos, m_sin): determine the type by the internal type, not by a method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07complex.c: check typenobu
* complex.c (nucomp_s_canonicalize_internal): determine the type by the internal type, not by a method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07complex.c, rational.c: no backrefnobu
Since r37702, parsing complex and rational do not use regexp. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07complex.c, rational.c: adjust indentnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-07complex.c, rational.c: simplified macro conditionsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-27defs/id.def: predefine to_f IDnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-27complex.c: use predefined IDsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-24complex.c, rational.c: remove dead codemrkn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23[DOC] nodoc internal methods/classesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30force fixablenobu
* complex.c (nucomp_hash): force hash values fixable. [ruby-core:85224] [Bug #14420] * rational.c (nurat_hash): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22use predefined IDskazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29complex.c: doc fixstomar
* complex.c: [DOC] fix grammar and typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-19freeze Complex and Rationalnobu
* complex.c (nucomp_s_new_internal, nucomp_loader): Complex instances are always frozen now. [Feature #13983] * rational.c (nurat_s_new_internal, nurat_loader): Rational instances are always frozen now. [Feature #13983] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-27complex.c: no overflownobu
* complex.c (rb_complex_infinite_p): get rid of overflow and unnecessary multiplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-27complex.c: no overflownobu
* complex.c (rb_complex_finite_p): get rid of overflow and unnecessary multiplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-27* complex.c: fix Complex#infinite? return value. Because nucomp_abs never ↵nobu
returns negative value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21complex.c: remove deprecated functionsnobu
* complex.c (rb_complex_set_real, rb_complex_set_imag): remove functions deprecated at 2.2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-22complex.c: optimize f_gt_p some casesmrkn
* complex.c (f_gt_p): optimize f_gt_p for specific types of arguments. * internal.h (rb_int_gt, rb_float_gt, rb_rational_cmp): exported. * numeric.c (rb_float_gt): rename from flo_gt and be exported. * numeric.c (rb_int_gt): rename from int_gt and be exported. * rational.c (rb_rational_cmp): rename from nurat_cmp and be exported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-22complex.c: optimize Kernel#Complexmrkn
* complex.c (nucomp_f_complex): use nucomp_s_convert directly. * complex.c (id_convert): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-18complex.c: optimize f_negatemrkn
* complex.c (f_negate): optimize for special numeric types. * complex.c (nucomp_expt): use rb_int_uminus instead of f_negate for fixnum value. * internal.h (rb_float_uminus, rb_rational_uminus): exported. * numeric.c (rb_float_uminus): rename from flo_uminus. * rational.c (rb_rational_uminus): rename from nurat_negate, and add assertion for the parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-18complex.c: refactoringmrkn
* complex.c (nucomp_abs): use rb_math_hypot directly. * complex.c (nucomp_arg): use rb_math_atan2 directly. * complex.c (imp2, m_{atan2,hypot}_bang, m_hypot): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-16complex.c: optimize Numeric#polar and Numeric#argmrkn
* complex.c (numeric_polar): optimize for Integer, Float, and Rational. * complex.c (numeric_arg): directly create the value of pi. * complex.c (f_negative_p): optimize for Integer, Float, and Rational. * rational.c (INT_NEGATIVE_P): move the definition into internal.h. * internal.h (INT_NEGATIVE_P): ditto. * numeric.c (rb_float_abs): rename from flo_abs and export to be used from other source files.. * internal.h (rb_float_abs): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-15complex.c: purge id_eqeq_p and limit return valuenobu
* complex.c (f_eqeq_p): use rb_equal. * complex.c (nucomp_eqeq_p): limit return value to true or false, instead of the result of the other as-is. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-14complex.c: optimizenobu
* complex.c (f_negative_p): use rb_num_negative_p instead of funcall. * complex.c (f_kind_of_p, f_numeric_p): cast down to int because rb_obj_is_kind_of is safe. * complex.c (f_signbit, f_tpositive_p): remove f_boolcast. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-13complex.c: refactoringmrkn
* complex.c (f_zero_p): return int rather than VALUE. * complex.c (rb_complex_mul): remove needless negate operations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-13complex.c: refactoringmrkn
* complex.c (f_one_p): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-13complex.c: refactoring and small optimizationmrkn
* complex.c (nucomp_expt): optimize the access to the numerator and denominator of a rational number. * complex.c (k_rational_p): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-13complex.c: refactoringmrkn
* complex.c (f_addsub, k_complex_p, k_float_p): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12complex.c: refactoringmrkn
* complex.c: refactor to use some specific macros and to reduce needless conversion by FIX2LONG. * complex.c (k_fixnum_p, k_bignum_p): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e