aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
Commit message (Collapse)AuthorAgeFilesLines
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-1/+0
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans2019-09-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cfuncs that use rb_scan_args with the : entry suffer similar keyword argument separation issues that Ruby methods suffer if the cfuncs accept optional or variable arguments. This makes the following changes to : handling. * Treats as **kw, prompting keyword argument separation warnings if called with a positional hash. * Do not look for an option hash if empty keywords are provided. For backwards compatibility, treat an empty keyword splat as a empty mandatory positional hash argument, but emit a a warning, as this behavior will be removed in Ruby 3. The argument number check needs to be moved lower so it can correctly handle an empty positional argument being added. * If the last argument is nil and it is necessary to treat it as an option hash in order to make sure all arguments are processed, continue to treat the last argument as the option hash. Emit a warning in this case, as this behavior will be removed in Ruby 3. * If splitting the keyword hash into two hashes, issue a warning, as we will not be splitting hashes in Ruby 3. * If the keyword argument is required to fill a mandatory positional argument, continue to do so, but emit a warning as this behavior will be going away in Ruby 3. * If keyword arguments are provided and the last argument is not a hash, that indicates something wrong. This can happen if a cfunc is calling rb_scan_args multiple times, and providing arguments that were not passed to it from Ruby. Callers need to switch to the new rb_scan_args_kw function, which allows passing of whether keywords were provided. This commit fixes all warnings caused by the changes above. It switches some function calls to *_kw versions with appropriate kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS is used. If creating new arguments, RB_PASS_KEYWORDS is used if the last argument is a hash to be treated as keywords. In open_key_args in io.c, use rb_scan_args_kw. In this case, the arguments provided come from another C function, not Ruby. The last argument may or may not be a hash, so we can't set keyword argument mode. However, if it is a hash, we don't want to warn when treating it as keywords. In Ruby files, make sure to appropriately use keyword splats or literal keywords when calling Cfuncs that now issue keyword argument separation warnings through rb_scan_args. Also, make sure not to pass nil in place of an option hash. Work around Kernel#warn warnings due to problems in the Rubygems override of the method. There is an open pull request to fix these issues in Rubygems, but part of the Rubygems tests for their override fail on ruby-head due to rb_scan_args not recognizing empty keyword splats, which this commit fixes. Implementation wise, adding rb_scan_args_kw is kind of a pain, because rb_scan_args takes a variable number of arguments. In order to not duplicate all the code, the function internals need to be split into two functions taking a va_list, and to avoid passing in a ton of arguments, a single struct argument is used to handle the variables previously local to the function.
* rb_numeric_quo: support ComplexNobuyoshi Nakada2019-08-101-0/+4
|
* Predefine some IDsNobuyoshi Nakada2019-08-031-4/+5
|
* Make float_decode_internal mantissa intNobuyoshi Nakada2019-08-021-21/+17
|
* Deduplicate common codeNobuyoshi Nakada2019-08-021-13/+5
|
* Expanded f_quoNobuyoshi Nakada2019-08-021-1/+10
|
* Expanded f_ceilNobuyoshi Nakada2019-08-021-8/+10
|
* Use RB_INTEGER_TYPE_PNobuyoshi Nakada2019-08-021-1/+6
|
* Expanded f_modNobuyoshi Nakada2019-08-021-8/+7
|
* Expanded f_numeratorNobuyoshi Nakada2019-07-161-3/+3
|
* Expanded f_denominatorNobuyoshi Nakada2019-07-161-3/+3
|
* Check exception flag as a bool [Bug #15987]Nobuyoshi Nakada2019-07-111-7/+1
|
* No TypeError at nil if exception: falsenobu2019-01-121-1/+3
| | | | | | [ruby-core:91021] [Bug #15525] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Remove duplicate macro definitionnobu2019-01-091-2/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: Optimize Complex#* and Complex#**mrkn2019-01-031-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [DOC] Add `or nil` to call-seq [ci skip]kazu2019-01-031-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* delete emacs mode lines [ci skip]shyouhei2018-12-271-6/+0
| | | | | | | These settings are now covered by .dir-locals.el. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* {complex,object,rational}.c: document exception: falsenormal2018-12-221-2/+4
| | | | | | | | 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
* Use idExceptionnobu2018-12-221-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Prefer rb_check_arity when 0 or 1 argumentsnobu2018-12-061-10/+6
| | | | | | | Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Prefer rb_check_arity when 0 or 1 argumentsnobu2018-12-041-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c (nurat_div): use the dedicated function nurat_to_fnobu2018-11-141-4/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2018-11-141-4/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: avoid division by zeroshyouhei2018-11-141-3/+6
| | | | | | | same as r65642. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* refine parse_ratnobu2018-11-081-25/+40
| | | | | | | | | | * rational.c (read_num): return the exponent instead of the divisor, to get rid of huge bignums. * rational.c (parse_rat): subtract exponents instead of reduction of powers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: small optimization of Complex#**nobu2018-10-201-2/+3
| | | | | | | | * 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
* Remove wrong conversionnobu2018-10-051-2/+1
| | | | | | | * rational.c (nurat_to_double): should return `double`, not `Float`. fix r64897. [Bug #15189] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix Rational of Floatnobu2018-10-021-3/+18
| | | | | | [ruby-core:89239] [Bug #15189] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: may be floatnobu2018-09-291-0/+10
| | | | | | | * 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
* Split assertion expressionsnobu2018-09-291-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: remove duplicate macrosnobu2018-09-041-3/+0
| | | | | | | * rational.c (RRATIONAL_SET_{NUM,DEN}): also defined in internal.h since r53887. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: simplify division resultnobu2018-09-011-0/+9
| | | | | | | * 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
* Add `exception:` keyword in Kernel#Rational()mrkn2018-03-151-37/+110
| | | | | | | | | | Support `exception:` keyword argument in `Kernel#Rational()`. If `exception:` is `false`, `Kernel#Rational()` returns `nil` if the given value cannot be interpreted as a rational 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@62759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Removed useless assertions [ci skip]nobu2018-03-091-2/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: removed redundant conditionsnobu2018-03-091-23/+10
| | | | | | Fixnums can be compared by object values themselves only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c, rational.c: no backrefnobu2018-03-071-6/+1
| | | | | | 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
* complex.c, rational.c: adjust indentnobu2018-03-071-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c, rational.c: simplified macro conditionsnobu2018-03-071-4/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Support two `to_r`-responding args in Rational()mrkn2018-02-271-0/+6
| | | | | | | | | * rational.c (nurat_s_convert): call `to_r` to convert non-Numeric objects also if argc == 2 in Rational(). * test/ruby/test_rational.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* defs/id.def: predefine to_f IDnobu2018-02-271-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c, rational.c: remove dead codemrkn2018-02-241-90/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: simplify a branch conditionmrkn2018-02-241-1/+1
| | | | | | * rational.c (nurat_s_convert): simplify a branch condition. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: removed needless calcnobu2018-02-241-1/+1
| | | | | | * rational.c (read_num): exp(0) is 1, no need to multiply. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: segfault on Rational exponentnobu2018-02-241-8/+14
| | | | | | | | | * rational.c (read_num): fix segfault on Rational() with positive but less than the length of fractional part exponent. should be negated to convert to divisor which is a reciprocal. [ruby-core:85783] [Bug #14547] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] nodoc internal methods/classesnobu2018-02-231-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* force fixablenobu2018-01-301-1/+1
| | | | | | | | | * 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
* use predefined IDskazu2018-01-221-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add missing/nan.cshyouhei2018-01-201-4/+0
| | | | | | | | | instead of scattering #ifdef HAVE_NANF here and there define our own nan() unless defined elsewhere. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* INFINITY is float. That of double is HUGE_VAL.shyouhei2018-01-191-1/+6
| | | | | | | | | | It seems HUGE_VAL is already used. Why not eliminate INTINITY. NAN is also float. That of double is called nan(). This is also fixed. Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e