summaryrefslogtreecommitdiff
path: root/rational.c
Commit message (Collapse)AuthorAgeFilesLines
* Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS2021-09-111-3/+3
|
* Make internal predicate functions to return simple booleanNobuyoshi Nakada2021-09-021-1/+1
|
* Remove unneeded comments in rational.cS-H-GAMELINKS2021-08-311-4/+0
|
* Use C99-defined macros to classify a floating-point numberNobuyoshi Nakada2021-08-271-2/+2
|
* Replace f_boolcast with RBOOL macroS.H2021-08-181-6/+5
| | | | | | | * Move f_boolcast definination * Remove f_boolcast macro defination * to
* Use Rational for Float#round with ndigits > 14Jeremy Evans2021-08-061-0/+6
| | | | | | | | | | | ndigits higher than 14 can result in values that are slightly too large due to floating point limitations. Converting to rational for the calculation and then back to float fixes these issues. Fixes [Bug #14635] Fixes [Bug #17183] Co-authored by: Yusuke Endoh <mame@ruby-lang.org>
* Use predefined IDsNobuyoshi Nakada2021-07-271-2/+2
|
* cdhash_cmp: can take rational literals卜部昌平2021-05-121-3/+10
| | | | | | | Rational literals are those integers suffixed with `r`. They tend to be a part of more complex expressions like `123/456r`, but in theory they can live alone. When such "bare" rational literals are passed to case-when branch, we have to take care of them. Fixes [Bug #17854]
* Rationalize floats in coerce [Bug #17572]Nobuyoshi Nakada2021-01-231-5/+11
|
* Make reciprocal properly of non-integral rational [Bug #17572]Nobuyoshi Nakada2021-01-231-1/+1
|
* Follow the NDEBUG given to the wholeNobuyoshi Nakada2021-01-071-2/+0
|
* Fix ArithmeticSequence#last and ArithmeticSequence#each for non-integer ↵Kenta Murata2020-12-091-8/+20
| | | | | | sequences (#3870) [Bug #17218] [ruby-core:100312]
* Removed canonicalization for mathnNobuyoshi Nakada2020-11-101-32/+3
|
* rational.c: convert a numerator to rational before calling fdiv in ↵Kenta Murata2020-10-261-1/+9
| | | | | | Kernel.Rational() (#3702) This makes `Rational(BigDecimal(1), 60) == Rational(1, 60)`. [Bug #16518]
* rational.c: try converting by to_int in Rational() (#3684)Kenta Murata2020-10-221-3/+31
| | | [Bug #12485]
* Don't redefine #rb_intern over and over againStefan Stüben2020-10-211-7/+4
|
* RARRAY_AREF: convert into an inline function卜部昌平2020-08-151-0/+1
| | | | | | RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function.
* Reduced working `Rational` object allocationsNobuyoshi Nakada2020-07-011-15/+28
| | | | When rationalizing negative values.
* Renamed `nurat_sub` compliant with `rb_rational_plus`Nobuyoshi Nakada2020-07-011-3/+3
|
* Added a few integer case short-circuitsNobuyoshi Nakada2020-07-011-1/+9
|
* Replaced f_odd_p with rb_int_odd_pNobuyoshi Nakada2020-07-011-10/+1
|
* parse_rat: do not goto into a branch卜部昌平2020-06-291-12/+15
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* rb_rational_cmp: do not goto into a branch卜部昌平2020-06-291-10/+11
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* 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.
* reroute redefinition of NDEBUG卜部昌平2020-04-211-0/+1
| | | | | NDEBUG can be defined via a command-line argument. Should take care of such situations.
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-3/+2
| | | Split ruby.h
* rb_rational_raw: convert num and den by to_intKenta Murata2020-01-171-0/+4
|
* rb_rational_raw: make a denominator always positiveKenta Murata2020-01-171-0/+4
|
* internal/rational.h: insert assertions in RATIONAL_SET_{NUM,DEN}Kenta Murata2020-01-171-1/+0
|
* rational.c: remove nurat_s_newKenta Murata2020-01-171-33/+13
|
* Make RATIONAL_SET_{NUM,DEN} static inline functionsKenta Murata2020-01-171-4/+4
|
* decouple internal.h headers卜部昌平2019-12-261-8/+15
| | | | | | | | | | | | | | | | | | 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).
* 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