Граф коммитов

334 Коммитов

Автор SHA1 Сообщение Дата
卜部昌平 2bc293e899 cdhash_cmp: can take rational literals
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]
2021-05-12 10:30:46 +09:00
Nobuyoshi Nakada 9efd590a13
Rationalize floats in coerce [Bug #17572] 2021-01-23 11:13:21 +09:00
Nobuyoshi Nakada a55eb9a2af
Make reciprocal properly of non-integral rational [Bug #17572] 2021-01-23 10:30:59 +09:00
Nobuyoshi Nakada 184e82e8f0
Follow the NDEBUG given to the whole 2021-01-07 16:52:10 +09:00
Kenta Murata fad3023e94
Fix ArithmeticSequence#last and ArithmeticSequence#each for non-integer sequences (#3870)
[Bug #17218]
[ruby-core:100312]
2020-12-09 18:48:59 +09:00
Nobuyoshi Nakada b958e2add8 Removed canonicalization for mathn 2020-11-10 11:14:15 +09:00
Kenta Murata 69837229d7
rational.c: convert a numerator to rational before calling fdiv in Kernel.Rational() (#3702)
This makes `Rational(BigDecimal(1), 60) == Rational(1, 60)`.
[Bug #16518]
2020-10-26 18:43:30 +09:00
Kenta Murata d23d5c3130
rational.c: try converting by to_int in Rational() (#3684)
[Bug #12485]
2020-10-22 17:59:52 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
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.
2020-08-15 12:09:26 +09:00
Nobuyoshi Nakada 49029811d9
Reduced working `Rational` object allocations
When rationalizing negative values.
2020-07-01 22:41:16 +09:00
Nobuyoshi Nakada 254bed3027
Renamed `nurat_sub` compliant with `rb_rational_plus` 2020-07-01 22:41:15 +09:00
Nobuyoshi Nakada 53d2bfd540
Added a few integer case short-circuits 2020-07-01 22:41:15 +09:00
Nobuyoshi Nakada 29ecce4d72
Replaced f_odd_p with rb_int_odd_p 2020-07-01 22:41:14 +09:00
卜部昌平 689dd3aecb parse_rat: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 d7eec15f8e rb_rational_cmp: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 32623150cd reroute redefinition of NDEBUG
NDEBUG can be defined via a command-line argument.  Should take care of
such situations.
2020-04-21 13:07:19 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Kenta Murata 5275d8bf4c
rb_rational_raw: convert num and den by to_int 2020-01-17 10:57:51 +09:00
Kenta Murata 47465ab1cc
rb_rational_raw: make a denominator always positive 2020-01-17 10:57:21 +09:00
Kenta Murata 07ce51c5aa
internal/rational.h: insert assertions in RATIONAL_SET_{NUM,DEN} 2020-01-17 10:06:58 +09:00
Kenta Murata fbc00c2d86
rational.c: remove nurat_s_new 2020-01-17 10:06:19 +09:00
Kenta Murata 019a0ed0c7
Make RATIONAL_SET_{NUM,DEN} static inline functions 2020-01-17 10:04:19 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
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).
2019-12-26 20:45:12 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Jeremy Evans 80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
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.
2019-09-25 11:18:49 -07:00
Nobuyoshi Nakada 52bd4716b4
rb_numeric_quo: support Complex 2019-08-10 23:19:24 +09:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
Nobuyoshi Nakada 9921b63ac4
Make float_decode_internal mantissa int 2019-08-02 19:04:38 +09:00
Nobuyoshi Nakada 6640eeb6db
Deduplicate common code 2019-08-02 18:11:05 +09:00
Nobuyoshi Nakada 19006b711d
Expanded f_quo 2019-08-02 11:28:24 +09:00
Nobuyoshi Nakada f9a0492b76
Expanded f_ceil 2019-08-02 11:26:58 +09:00
Nobuyoshi Nakada ffe4a6ebf9
Use RB_INTEGER_TYPE_P 2019-08-02 11:26:58 +09:00
Nobuyoshi Nakada 6de61fb9ed
Expanded f_mod 2019-08-02 11:26:51 +09:00
Nobuyoshi Nakada ca524bcd49
Expanded f_numerator 2019-07-16 08:15:05 +09:00
Nobuyoshi Nakada 34019a22eb
Expanded f_denominator 2019-07-16 07:59:30 +09:00
Nobuyoshi Nakada 3e7d002118
Check exception flag as a bool [Bug #15987] 2019-07-11 20:04:29 +09:00
nobu 62c17a2f21 No TypeError at nil if exception: false
[ruby-core:91021] [Bug #15525]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12 05:02:58 +00:00
nobu bc27f87889 Remove duplicate macro definition
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 08:43:50 +00:00
mrkn 673ff731c1 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
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 06:19:17 +00:00
kazu bace0d4cdc [DOC] Add `or nil` to call-seq [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 05:51:18 +00:00
shyouhei bc64df876e delete emacs mode lines [ci skip]
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
2018-12-27 06:12:09 +00:00
normal 9b9fe826fd {complex,object,rational}.c: document exception: false
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-22 22:39:31 +00:00
nobu 8ef2aae2d0 Use idException
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 10:23:06 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
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
2018-12-06 07:49:24 +00:00
nobu 4b85e88174 Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04 02:24:15 +00:00
nobu ed778c2a89 rational.c (nurat_div): use the dedicated function nurat_to_f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-14 14:12:30 +00:00
svn 33758ded08 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-14 09:53:13 +00:00