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

900 Коммитов

Автор SHA1 Сообщение Дата
Kouhei Yanagita 24e33b84b5 Remove Numeric#ceildiv 2022-08-12 15:57:52 +09:00
Kouhei Yanagita 4165fd0e76 Add Numeric#ceildiv and Integer#ceildiv 2022-08-12 15:57:52 +09:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Kouhei Yanagita a4721ec6cd [DOC] Fix documentation of Numeric#div: Complex does not have #div 2022-06-03 14:35:47 +09:00
Kouhei Yanagita 8b4d2a5014
[DIC] Fix typo in documentation 2022-05-27 20:18:54 +09:00
Grant Hutchins 59c81274aa Use correct capitalization of "NaN" in docs 2022-04-13 15:44:36 -04:00
Nobuyoshi Nakada 300f4677c9
[DOC] Use simple references to operator methods
Method references is not only able to be marked up as code, also
reflects `--show-hash` option.
The bug that prevented the old rdoc from correctly parsing these
methods was fixed last month.
2022-03-26 21:13:16 +09:00
Burdette Lamar 7f93b7dc88
[DOC] Fix formatting for What's Here in IO (#5719)
* Fix formatting for What's Here in IO

* Repair formatting in What's Heres in numeric.c

* Fix formatting for What's Here in IO
2022-03-25 15:43:46 -05:00
Koichi ITO 045ab1d056 [DOC] Fix a typo in `Integer#chr` example
The current example raises the following error.

```ruby
0..chr # => undefined local variable or method `chr' for main:Object (NameError)
```

This PR updates the example to produce the expected behavior.

```ruby
0.chr # => "\x00"
```
2022-02-13 15:48:01 +09:00
Nobuyoshi Nakada 50c972a1ae
[DOC] Simplify operator method references 2022-02-12 12:38:36 +09:00
Nobuyoshi Nakada 16fdc1ff46
[DOC] Fix broken links to literals.rdoc 2022-02-08 01:27:52 +09:00
Nobuyoshi Nakada bc5662d9d8
[DOC] Simplify links to global methods 2022-02-08 01:18:56 +09:00
Peter Zhu a32e5e1b97 [DOC] Use RDoc link style for links in the same class/module
I used this regex:

(?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Peter Zhu f9a2802bc5 [DOC] Use RDoc link style for links to other classes/modules
I used this regex:

([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Nobuyoshi Nakada 6a6227e016 Shifting zero always results in zero [Bug #18517] 2022-01-27 14:00:33 +09:00
Nobuyoshi Nakada 069cca6f74
Negative RBOOL usage 2022-01-01 17:02:04 +09:00
Nobuyoshi Nakada 77ee47188e
Make the internal predict `int_zero_p` return a bool 2022-01-01 17:01:40 +09:00
Nobuyoshi Nakada 40e7aefeba Remove obsolete Fixnum and Bignum 2021-12-28 18:35:03 +09:00
Nobuyoshi Nakada 454b4da763
[DOC] Integer.try_convert [ci skip] 2021-12-08 17:59:16 +09:00
Burdette Lamar 28fb6d6b9e
Adding links to literals and Kernel (#5192)
* Adding links to literals and Kernel
2021-12-03 07:12:28 -06:00
Jeremy Evans fe1725236c Don't call + and < in Integer.times for !FIXNUM
The methods aren't called for FIXNUM, and it's best to have
consistent behavior.

Fixes [Bug #18377]
2021-12-01 16:21:50 -08:00
Burdette Lamar eac7c63538
Enhanced RDoc for numeric.c (#5184)
Adds remarks about literals and Kernel methods to Float and Integer.
2021-11-27 13:07:37 -06:00
Burdette Lamar e469ebd7d3
Correct indentation error in numeric.c (#5178) 2021-11-25 13:14:10 -06:00
Burdette Lamar 635efa594a
Whats here for float (#5170)
* What's Here for Float
2021-11-24 17:44:27 -06:00
Burdette Lamar 9faa599196
Enhanced RDoc for Float#floor (#5167)
* Enhanced RDoc for Float#floor

* Enhanced RDoc for Float

* Enhanced RDoc for Float
2021-11-24 15:15:12 -06:00
Burdette Lamar 7c3041047e
Enhanced RDoc for Float#prev_float (#5162)
* Enhanced RDoc for Float#prev_float
2021-11-24 08:34:30 -06:00
Burdette Lamar df8f858115
Enhanced RDoc for Float#next_float (#5160)
* Enhanced RDoc for Float#next_float
2021-11-23 15:38:28 -06:00
Burdette Lamar da832d6c2a
What's Here section for Integer (#5155)
* What's Here section for Integer
2021-11-22 19:04:25 -06:00
Burdette Lamar e42f994f6b
Enhanced RDoc for Float (#5153)
Treats:

    #>
    #>=
    #<
    #<=
    #eql?
    #nan?
    #infinite?
    #finite?
2021-11-22 14:57:17 -06:00
Burdette Lamar 86ad878e6a
Enhanced RDoc for Float (#5150)
Treated (or previously treated):

    #quo
    #%
    #divmod
    #**`
    #eql?
    #<=>
    #==
    #hash
2021-11-20 17:21:30 -06:00
Burdette Lamar e0c38742a2
Enhanced RDoc for Float (#5144)
Treats:

    #to_s
    #coerce
    #+
    #-
    #*
    #/
2021-11-19 12:16:16 -06:00
Jeremy Evans b08dacfea3
Optimize dynamic string interpolation for symbol/true/false/nil/0-9
This provides a significant speedup for symbol, true, false,
nil, and 0-9, class/module, and a small speedup in most other cases.

Speedups (using included benchmarks):
:symbol        :: 60%
0-9            :: 50%
Class/Module   :: 50%
nil/true/false :: 20%
integer        :: 10%
[]             :: 10%
""             :: 3%

One reason this approach is faster is it reduces the number of
VM instructions for each interpolated value.

Initial idea, approach, and benchmarks from Eric Wong. I applied
the same approach against the master branch, updating it to handle
the significant internal changes since this was first proposed 4
years ago (such as CALL_INFO/CALL_CACHE -> CALL_DATA). I also
expanded it to optimize true/false/nil/0-9/class/module, and added
handling of missing methods, refined methods, and RUBY_DEBUG.

This renames the tostring insn to anytostring, and adds an
objtostring insn that implements the optimization. This requires
making a few functions non-static, and adding some non-static
functions.

This disables 4 YJIT tests.  Those tests should be reenabled after
YJIT optimizes the new objtostring insn.

Implements [Feature #13715]

Co-authored-by: Eric Wong <e@80x24.org>
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
Co-authored-by: Koichi Sasada <ko1@atdot.net>
2021-11-18 15:10:20 -08:00
Burdette Lamar f3dcb4bbf7
Enhanced RDoc for Integer (#5139)
Treats:

    #<<
    #>>
    #to_s
2021-11-18 08:28:04 -06:00
Burdette Lamar cb69c19e8a
Enhanced RDoc for Integer (#5138)
Treats:

    #times
    #round
    #floor
    #ceil
    #truncate
    ::sqrt
2021-11-17 16:00:50 -06:00
Burdette Lamar 4acac918f4
Enhanced RDoc for Integer (#5134)
Treated:

    #==
    #<=>
    #<
    #<=
    #>
    #>=
    #&
    #|
    #^
2021-11-17 12:51:32 -06:00
Burdette Lamar d8d5488631
Enhanced RDoc for Integer (#5120)
Treated:

    #+
    #-
    #*
    #fdiv
    #/
    #div
    #**
    #[]
    #digits
    #upto
    #downto
2021-11-16 13:42:05 -06:00
Burdette Lamar f31b7f0522
Enhanced RDoc for Integer (#5118)
Treats:

#allbits?
#anybits?
#nobits?
#succ
#pred
#chr`
#to_s
#+
#-
2021-11-15 13:52:23 -06:00
Yusuke Endoh 15bc1ae41e Revert "Enhanced RDoc for Integer (#5099)"
This reverts commit fc456adc6a.

It broke the CI check.

https://github.com/ruby/ruby/runs/4207922247?check_suite_focus=true#step:3:4
```
numeric.c:3518: *     255.chr(Encoding::UTF_8) # => "ÿ"
Error: Process completed with exit code 1.
```
2021-11-15 14:50:03 +09:00
Burdette Lamar fc456adc6a
Enhanced RDoc for Integer (#5099)
Treats:

    #allbits?
    #anybits?
    #nobits?
    #succ
    #pred
    #chr`
    #to_s
    #+
    #-
2021-11-13 14:48:57 -06:00
Nobuyoshi Nakada 7cc4e147fc
Get rid of implicit expansion to `long double` on ix86 2021-11-08 18:35:22 +09:00
Burdette Lamar f8bbd608c9
Enhanced RDoc for Numeric (#4994)
Treats:

    #eql?
    #<+>
    #floor
    #ceil
    #round
    #truncate
    #step
2021-10-28 15:11:11 -05:00
Nobuyoshi Nakada 26353c75a9 Embed bare `double` if `sizeof(double) == sizeof(VALUE)` 2021-10-27 02:05:06 +09:00
Nobuyoshi Nakada e3a783b141 Align `RFloat` at VALUE boundary 2021-10-27 02:05:06 +09:00
Nobuyoshi Nakada afdca0e780
Fix unaligned access to `double` in RFloat 2021-10-26 20:17:00 +09:00
Burdette Lamar 3e96b94eba
Enhanced RDoc for Numeric (#4991)
Treated:

    #@-
    #fdiv
    #div
    #abs
    #zero?
    #nonzero?
    #to_int
    #positive?
    #negative?
2021-10-19 12:00:22 -05:00
Burdette Lamar 012cafa5c7
Enhanced RDoc for numerics (#4982)
Treats:

    Numeric#coerce
    Numeric#clone
    Numeric#dup
    Numeric#@+ (unary plus)
    Numeric#i
    Float#coerce
2021-10-18 18:35:06 -05:00
Burdette Lamar 5d975684da
Enhanced RDoc for remainder (#4975)
Treats Numeric#remainder and Integer#remainder.
2021-10-15 16:20:52 -05:00
Burdette Lamar 37ea909f42
Enhanced RDoc for divmod (#4973)
Treats:

    Integer#divmod
    Float#divmod
    Numeric#divmod
2021-10-15 12:51:37 -05:00
Burdette Lamar 2043c2e7e4
Enhanced RDoc for numeric.c (#4964)
Treats Integer#% and Float#%.
2021-10-15 11:57:49 -05:00
Burdette Lamar bb66729b5f
Enhanced RDoc for Numeric#% (#4954) 2021-10-12 08:06:05 -05:00
S-H-GAMELINKS d25af1f44e Add flo_ndigits function 2021-10-10 09:29:53 +09:00
S.H b8c3a84bdd
Refactor and Using RBOOL macro 2021-09-15 08:11:05 +09:00
S-H-GAMELINKS 83a5e2bb5c Using RB_FLOAT_TYPE_P macro 2021-09-12 11:16:31 +09:00
S-H-GAMELINKS af5826a25e Replace RB_TYPE_P macro to FIXNUM_P and RB_INTEGER_TYPE_P macro 2021-09-12 11:16:09 +09:00
S-H-GAMELINKS 9784f6685e Using NIL_P macro instead of RB_TYPE_P macro 2021-09-11 09:15:21 +09:00
S-H-GAMELINKS 032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
Nobuyoshi Nakada 465bd972ec
[DOC] Move rdoc of Integer#abs to numeric.rb [ci skip] 2021-08-30 13:33:52 +09:00
Nobuyoshi Nakada 04be8e84db
Use C99-defined macros to classify a floating-point number 2021-08-27 12:41:30 +09:00
John Hawthorn d668cd188c rb_fix2uint should use FIXNUM_NEGATIVE_P
rb_num_negative_int_p is equivalent to calling the "<" method on
Integer (and checking whether it is overridden), where in this case we
are interested in whether the "actual" value can fit inside an unsigned
int.

This also was slow because rb_num_negative_int_p calls
rb_method_basic_definition_p, doing a method lookup to check for < being
overridden.

This replaces the check in both rb_fix2uint and rb_fix2ushort with FIXNUM_NEGATIVE_P which simply checks
whether the VALUE is signed.
2021-08-18 18:24:37 +09:00
Jeremy Evans d16b68cb22 Use Rational for Float#round with ndigits > 14
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>
2021-08-06 15:03:51 -07:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Jeremy Evans 9931e2f509 Improve performance of Integer#digits
This speeds up performance by multiple orders of magnitude for
large integers.

Fixes [Bug #14391]

Co-authored-by: tompng (tomoya ishida) <tomoyapenguin@gmail.com>
2021-07-29 15:19:12 -07:00
Jeremy Evans 35e467080c Make Float#floor with ndigits argument handle error
The previous implementation could result in a returned
float that is 1/(10**ndigits) too low.  First try adding
one before dividing, and if that results in a value that is
greater than the initial number, then try the original
calculation.

Spec added for ciel, but the issue doesn't appear to affect
ciel, at least not for the same number.  If the issue does
effect ciel, a similar fix could probably work for it.

Fixes [Bug #18018]
2021-07-27 11:00:45 -07:00
Nobuyoshi Nakada 301d194ee3 Add Integer.try_convert [Feature #15211] 2021-07-16 17:49:53 +09:00
Burdette Lamar c1741df1a1 What's Here for Numeric and Comparable 2021-06-21 10:38:16 -07:00
S.H 3208a5df2d
Improve perfomance for Integer#size method [Feature #17135] (#3476)
* Improve perfomance for Integer#size method [Feature #17135]

* re-run ci

* Let MJIT frame skip work for Integer#size

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2021-06-04 21:57:21 -07:00
Jeremy Evans f516379853 Fix Enumerator::ArithmeticSequence handling of float ranges
Depending on the float range, there could be an off-by-one error,
where the last result that should be in the range was missed. Fix
this by checking if the computed value for the expected value
outside the range is still inside the range, and if so, increment
the step size.

Fixes [Bug #16612]
2021-05-29 08:56:15 -07:00
S.H ce36097748
Refactor num_zero_p function (#4522) 2021-05-23 17:41:03 -07:00
Jeremy Evans aaab3b1de9 Fix integer/float remainder with infinity argument of opposite sign
Previously, the result was incorrect:

4.remainder(-Float::INFINITY)
Before: => NaN
After: => 4

4.2.remainder(-Float::INFINITY)
Before: => NaN
After: => 4.2

Fixes [Bug #6120]
2021-03-12 07:35:18 -08:00
S.H efd19badf4
Improve performance some Numeric methods [Feature #17632] (#4190) 2021-02-19 11:11:19 -08:00
S.H fad7908a5d
Improve performance Float#positive? and Float#negative? [Feature #17614] (#4160) 2021-02-08 20:29:42 -08:00
S-H-GAMELINKS 25d506a318 Move rb_big_isqrt declaration 2021-01-31 09:23:51 +09:00
Takashi Kokubun 9d1475c621
Fix JIT link failures
forgotten in https://github.com/ruby/ruby/pull/4018
2021-01-18 14:52:33 -08:00
S.H daec5f9edc
Improve performance some Float methods [Feature #17498] (#4018) 2021-01-01 18:39:07 -08:00
Takashi Kokubun dbb4f19969
Allow inlining Integer#-@ and #~
```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' benchmark/mjit_integer.yml --filter '(comp|uminus)'
before --jit: ruby 3.0.0dev (2020-12-23T05:41:44Z master 0dd4896175) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-23T06:25:41Z master 8887d78992) +JIT [x86_64-linux]
last_commit=Allow inlining Integer#-@ and #~
Calculating -------------------------------------
                     before --jit  after --jit
        mjit_comp(1)      44.006M      70.417M i/s -     40.000M times in 0.908967s 0.568042s
      mjit_uminus(1)      44.333M      68.422M i/s -     40.000M times in 0.902255s 0.584603s

Comparison:
                     mjit_comp(1)
         after --jit:  70417331.4 i/s
        before --jit:  44005980.4 i/s - 1.60x  slower

                   mjit_uminus(1)
         after --jit:  68422468.8 i/s
        before --jit:  44333371.0 i/s - 1.54x  slower
```
2020-12-22 22:32:19 -08:00
Alan Wu c59b9a8c0c Move docs for Integer#bit_length [ci skip] 2020-12-14 20:01:55 -05:00
S-H-GAMELINKS 52bca75cde Remove unused function declarations 2020-12-12 14:12:40 +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
S-H-GAMELINKS 8cbd5f218b rename 2020-11-20 11:47:47 +09:00
S-H-GAMELINKS c11c25baef fix code 2020-11-20 11:47:47 +09:00
S-H-GAMELINKS d79cdcb113 add flo_prev_or_next func 2020-11-20 11:47:47 +09:00
Kenta Murata f754b42285
numeric.c, range.c: prohibit zero step
* numeric.c: prohibit zero step in Numeric#step

* range.c: prohibit zero step in Range#step

* Fix ruby-spec

[Feature #15573]
2020-10-23 15:26:51 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Nobuyoshi Nakada dd77796f1c
Hoisted out ensure_cmp which checks the comparison succeeded 2020-10-02 21:30:07 +09:00
Nobuyoshi Nakada 89ca842dcc
Ensure that the comparison succeeded [Bug #17205] 2020-10-02 11:02:45 +09:00
Peter Zhu f7bd9f0750 Fix unsigned int overflow in error message for chr
The error message has an integer overflow because it treats an unsigned int as a signed int.

Before:
```
> 3_000_000_000.chr
-1294967296 out of char range (RangeError)
```

After:
```
> 3_000_000_000.chr
3000000000 out of char range (RangeError)
```

Redmine ticket: https://bugs.ruby-lang.org/issues/17186
2020-09-30 00:31:59 +09:00
S-H-GAMELINKS 9db5d63ece [DOC] Use oracle url instead of sun url
[ci skip]
2020-08-05 08:04:58 +09:00
Kazuhiro NISHIYAMA 946cd6c534
Use https instead of http 2020-07-28 19:51:54 +09:00
卜部昌平 802bcd3ec8 fix MJIT link error 2020-07-13 08:56:18 +09:00
卜部昌平 9721f477c7 inline Primitive.cexpr!
We can obtain the verbatim source code of Primitive.cexpr!.  Why not
paste that content into the JITed program.
2020-07-13 08:56:18 +09:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 03354feb6a fix_pow: 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
卜部昌平 250189f54f int_pow: 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
卜部昌平 bf19820bb3 flo_to_s: 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
Takashi Kokubun 0703e01471
Mark some Integer methods as inline (#3264) 2020-06-27 10:07:47 -07:00
Takashi Kokubun 95b0fed371
Make Integer#zero? a separated method and builtin (#3226)
A prerequisite to fix https://bugs.ruby-lang.org/issues/15589 with JIT.
This commit alone doesn't make a significant difference yet, but I thought
this commit should be committed independently.

This method override was discussed in [Misc #16961].
2020-06-20 14:55:09 -07:00
S.H eaf76be087
Remove unused else if statements in int_even_p func (#3220)
* remove else if & rb_funcall

* fix int_even_p impl

* fix rb_int_odd_p implementation
2020-06-16 10:13:54 -07:00
S.H 84160dc29b
Add static modifier for rb_int_ceil & rb_int_floor (#3217) 2020-06-16 17:47:59 +09:00
Yusuke Endoh 42abad2464 numeric.c: optimize `float ** 2` case by fastpath
It would be a relatively frequent case.  It is still slower than
`float * float` because `*` has a dedicated VM instruction (opt_mult),
though.
2020-05-12 02:14:27 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00