summaryrefslogtreecommitdiff
path: root/numeric.c
AgeCommit message (Collapse)Author
2021-12-08[DOC] Integer.try_convert [ci skip]Nobuyoshi Nakada
2021-12-03Adding links to literals and Kernel (#5192)Burdette Lamar
* Adding links to literals and Kernel Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-12-01Don't call + and < in Integer.times for !FIXNUMJeremy Evans
The methods aren't called for FIXNUM, and it's best to have consistent behavior. Fixes [Bug #18377] Notes: Merged: https://github.com/ruby/ruby/pull/5199
2021-11-27Enhanced RDoc for numeric.c (#5184)Burdette Lamar
Adds remarks about literals and Kernel methods to Float and Integer. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-25Correct indentation error in numeric.c (#5178)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-24Whats here for float (#5170)Burdette Lamar
* What's Here for Float Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-24Enhanced RDoc for Float#floor (#5167)Burdette Lamar
* Enhanced RDoc for Float#floor * Enhanced RDoc for Float * Enhanced RDoc for Float Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-24Enhanced RDoc for Float#prev_float (#5162)Burdette Lamar
* Enhanced RDoc for Float#prev_float Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-23Enhanced RDoc for Float#next_float (#5160)Burdette Lamar
* Enhanced RDoc for Float#next_float Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-22What's Here section for Integer (#5155)Burdette Lamar
* What's Here section for Integer Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-22Enhanced RDoc for Float (#5153)Burdette Lamar
Treats: #> #>= #< #<= #eql? #nan? #infinite? #finite? Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-20Enhanced RDoc for Float (#5150)Burdette Lamar
Treated (or previously treated): #quo #% #divmod #**` #eql? #<=> #== #hash Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-19Enhanced RDoc for Float (#5144)Burdette Lamar
Treats: #to_s #coerce #+ #- #* #/ Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-18Optimize dynamic string interpolation for symbol/true/false/nil/0-9Jeremy Evans
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> Notes: Merged: https://github.com/ruby/ruby/pull/5002 Merged-By: jeremyevans <code@jeremyevans.net>
2021-11-18Enhanced RDoc for Integer (#5139)Burdette Lamar
Treats: #<< #>> #to_s Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-17Enhanced RDoc for Integer (#5138)Burdette Lamar
Treats: #times #round #floor #ceil #truncate ::sqrt Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-17Enhanced RDoc for Integer (#5134)Burdette Lamar
Treated: #== #<=> #< #<= #> #>= #& #| #^ Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-16Enhanced RDoc for Integer (#5120)Burdette Lamar
Treated: #+ #- #* #fdiv #/ #div #** #[] #digits #upto #downto Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-15Enhanced RDoc for Integer (#5118)Burdette Lamar
Treats: #allbits? #anybits? #nobits? #succ #pred #chr` #to_s #+ #- Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-15Revert "Enhanced RDoc for Integer (#5099)"Yusuke Endoh
This reverts commit fc456adc6a62d09b755243b8c8f190934b9965d6. 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-13Enhanced RDoc for Integer (#5099)Burdette Lamar
Treats: #allbits? #anybits? #nobits? #succ #pred #chr` #to_s #+ #- Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-11-08Get rid of implicit expansion to `long double` on ix86Nobuyoshi Nakada
2021-10-28Enhanced RDoc for Numeric (#4994)Burdette Lamar
Treats: #eql? #<+> #floor #ceil #round #truncate #step Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-27Embed bare `double` if `sizeof(double) == sizeof(VALUE)`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5027
2021-10-27Align `RFloat` at VALUE boundaryNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5027
2021-10-26Fix unaligned access to `double` in RFloatNobuyoshi Nakada
2021-10-19Enhanced RDoc for Numeric (#4991)Burdette Lamar
Treated: #@- #fdiv #div #abs #zero? #nonzero? #to_int #positive? #negative? Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-18Enhanced RDoc for numerics (#4982)Burdette Lamar
Treats: Numeric#coerce Numeric#clone Numeric#dup Numeric#@+ (unary plus) Numeric#i Float#coerce Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-15Enhanced RDoc for remainder (#4975)Burdette Lamar
Treats Numeric#remainder and Integer#remainder. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-15Enhanced RDoc for divmod (#4973)Burdette Lamar
Treats: Integer#divmod Float#divmod Numeric#divmod Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-15Enhanced RDoc for numeric.c (#4964)Burdette Lamar
Treats Integer#% and Float#%. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-12Enhanced RDoc for Numeric#% (#4954)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-10-10Add flo_ndigits functionS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4926
2021-09-15Refactor and Using RBOOL macroS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4837 Merged-By: nobu <nobu@ruby-lang.org>
2021-09-12Using RB_FLOAT_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4821
2021-09-12Replace RB_TYPE_P macro to FIXNUM_P and RB_INTEGER_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4816
2021-09-11Using NIL_P macro instead of RB_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4806
2021-09-11Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4805
2021-08-30[DOC] Move rdoc of Integer#abs to numeric.rb [ci skip]Nobuyoshi Nakada
2021-08-27Use C99-defined macros to classify a floating-point numberNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4783
2021-08-18rb_fix2uint should use FIXNUM_NEGATIVE_PJohn Hawthorn
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. Notes: Merged: https://github.com/ruby/ruby/pull/4747
2021-08-06Use Rational for Float#round with ndigits > 14Jeremy Evans
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> Notes: Merged: https://github.com/ruby/ruby/pull/4682
2021-08-02Using RBOOL macroS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4695 Merged-By: nobu <nobu@ruby-lang.org>
2021-07-29Improve performance of Integer#digitsJeremy Evans
This speeds up performance by multiple orders of magnitude for large integers. Fixes [Bug #14391] Co-authored-by: tompng (tomoya ishida) <tomoyapenguin@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/4584
2021-07-27Make Float#floor with ndigits argument handle errorJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/4681
2021-07-16Add Integer.try_convert [Feature #15211]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4654
2021-06-21What's Here for Numeric and ComparableBurdette Lamar
2021-06-04Improve perfomance for Integer#size method [Feature #17135] (#3476)S.H
* 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> Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2021-05-29Fix Enumerator::ArithmeticSequence handling of float rangesJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/4434
2021-05-23Refactor num_zero_p function (#4522)S.H
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>