summaryrefslogtreecommitdiff
path: root/numeric.c
AgeCommit message (Collapse)Author
2025-04-07Fix `Integer.sqrt` to never exceed actual valueYusuke Endoh
`Integer.sqrt` uses `sqrt(3)` from libm for small values. This method must return a value less than or equal to the actual integer square root, but libm's sqrt does not always guarantee that. This change corrects that by decrementing the result if necessary. Fixes [Bug #21217] Notes: Merged: https://github.com/ruby/ruby/pull/13076
2025-02-27[DOC] Fix indentationNobuyoshi Nakada
Not to make preceding paragraphs a code block. Notes: Merged: https://github.com/ruby/ruby/pull/12820
2025-01-02[DOC] Exclude 'Class' and 'Module' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2025-01-02[DOC] Exclude 'Method' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2024-12-17[DOC] Fix example in Numeric#to_intBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/12372
2024-12-02Correct order of listed methodsBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/12229
2024-10-22Rewrite Numeric#dup and Numeric#+@ in Ruby (#11933)Takashi Kokubun
Notes: Merged-By: k0kubun <[email protected]>
2024-10-07[DOC] Move each `Float#to_s` example item by itemNobuyoshi Nakada
Like as +half+ option in Float#round. If the body of the preceding list items and the following code block are indented at the same position, the code block is parsed as a list continuation. [Fixes GH-11683]
2024-09-10[DOC] Fix linksBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/11527
2024-07-30Fix ceil when ndigits is largePeter Zhu
[Bug #20654] This commit fixes Integer#ceil and Float#ceil when the number is negative and ndigits is large such that 10**ndigits is a bignum. Previously, it would return 0 in such cases. However, this would cause unexpected behaviour such as: puts 1.ceil(-5) # => 100000 puts 1.ceil(-10) # => 10000000000 puts 1.ceil(-20) # => 0 This commit changes the last result so that it will return 100000000000000000000. Notes: Merged: https://github.com/ruby/ruby/pull/11257
2024-07-30Fix floor when ndigits is largePeter Zhu
[Bug #20654] This commit fixes Integer#floor and Float#floor when the number is negative and ndigits is large such that 10**ndigits is a bignum. Previously, it would return 0 in such cases. However, this would cause unexpected behaviour such as: puts -1.floor(-5) # => -100000 puts -1.floor(-10) # => -10000000000 puts -1.floor(-20) # => 0 This commit changes the last result so that it will return -100000000000000000000. Notes: Merged: https://github.com/ruby/ruby/pull/11257
2024-07-29Revert moving things to RubyAaron Patterson
This is slowing down benchmarks on x86, so lets revert it for now. Notes: Merged: https://github.com/ruby/ruby/pull/11275
2024-07-26Doc for some #ceil and #floorBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/11245
2024-07-26Doc for some #ceil and #floorBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/11245
2024-07-09[DOC] Doc for Float#ceil (#11125)Burdette Lamar
2024-07-09[DOC] Use backticks instead of HTML tagsPeter Zhu
2024-07-09[DOC] Fix granularity calculationPeter Zhu
The granularity is calculated as `10 ** ndigits.abs` rather than `ndigits.abs * 10`. For example, if `ndigits` is `-2`, it should be `10 ** 2 == 100` rather than `2 * 10 == 20`.
2024-07-08Doc fixesBurdetteLamar
2024-07-03[DOC] Doc for Integer#floor (#11077)Burdette Lamar
2024-07-03move Integer#downto to RubyAaron Patterson
Speeds up ChunkyPNG. The interpreter is about 70% faster: ``` before: ruby 3.4.0dev (2024-07-03T15:16:17Z master 786cf9db48) [arm64-darwin23] after: ruby 3.4.0dev (2024-07-03T15:32:25Z ruby-downto 0b8b744ce2) [arm64-darwin23] ---------- ----------- ---------- ---------- ---------- ------------- ------------ bench before (ms) stddev (%) after (ms) stddev (%) after 1st itr before/after chunky-png 892.2 0.1 526.3 1.0 1.65 1.70 ---------- ----------- ---------- ---------- ---------- ------------- ------------ Legend: - after 1st itr: ratio of before/after time for the first benchmarking iteration. - before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup. ``` YJIT is 2.5x faster: ``` before: ruby 3.4.0dev (2024-07-03T15:16:17Z master 786cf9db48) +YJIT [arm64-darwin23] after: ruby 3.4.0dev (2024-07-03T15:32:25Z ruby-downto 0b8b744ce2) +YJIT [arm64-darwin23] ---------- ----------- ---------- ---------- ---------- ------------- ------------ bench before (ms) stddev (%) after (ms) stddev (%) after 1st itr before/after chunky-png 709.4 0.1 278.8 0.3 2.35 2.54 ---------- ----------- ---------- ---------- ---------- ------------- ------------ Legend: - after 1st itr: ratio of before/after time for the first benchmarking iteration. - before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup. ```
2024-06-29Doc for Integer#ceilBurdetteLamar
2024-04-26[DOC] Enhance `Numeric#nonzero?` docArtur
Add `zero?` as a related method
2024-04-08Reducing the number of divisions in `rb_fix_digits`Reznov
2024-03-27Register rb_fix_to_s_static as global right after creatingPeter Zhu
If a GC runs right during creating a rb_fix_to_s_static, it may cause the previous ones to become swept by the GC because they have not been registered by rb_vm_register_global_object.
2024-03-18Faster Integer.sqrt for large bignumtompng
Integer.sqrt uses Newton's method. This pull request reduces the precision which was unnecessarily high in each calculation step.
2024-03-06Refactor VM root modulesJean Boussier
This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
2024-02-17Use `defined?(yield)` and `SIZED_ENUMERATOR`Nobuyoshi Nakada
Prefer built-in features over method calls that may be overridden.
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-12Replace assert with RUBY_ASSERT in numeric.cPeter Zhu
assert does not print the bug report, only the file and line number of the assertion that failed. RUBY_ASSERT prints the full bug report, which makes it much easier to debug.
2024-01-06Tweak to Integer What's HereBurdetteLamar
2024-01-06Tweak to Float What's HereBurdetteLamar
2024-01-06Tweak to Float What's HereBurdetteLamar
2024-01-06[DOC] Fix indentation in Numeric#stepPeter Zhu
2024-01-06[DOC] Fix typo in call-seq for Float#roundPeter Zhu
2024-01-01[DOC] Fix alignment of values for Integer#divPeter Zhu
2024-01-01[DOC] Fix indentation for Integer#divPeter Zhu
The line was indented, which caused it to be treated as a code block.
2023-12-29[DOC] Fix indentation for Numeric#stepPeter Zhu
The documentation was indented one level too deep, which causes RDoc to generate it all as a code block.
2023-12-26[DOC] Fix documentation for Numeric#eql?Peter Zhu
+==+ does not format properly, so we should use <tt>==</tt> instead.
2023-12-07Use free with ruby_dtoaJohn Hawthorn
In ae0ceafb0c0d05cc80623b525070255e3abb34ef ruby_dtoa was switched to use malloc instead of xmalloc, which means that consumers should be using free instead of xfree. Otherwise we will artificially shrink oldmalloc_increase_bytes.
2023-11-29[Bug #17037] Improve accuracy of division near precision limitsNobuyoshi Nakada
When dividing near the precision limit of `double`, use Bignum division to get rid of rounding errors.
2023-10-15[DOC] Fix the argument name in the Numeric#step docKouhei Yanagita
2023-10-14[Bug #19926] Fix Range#size for ranges with a Rational endpointKouhei Yanagita
2023-09-27[DOC] Missing comment markersNobuyoshi Nakada
2023-09-07Rewrite Integer#times in Ruby (#8388)Takashi Kokubun
Notes: Merged-By: k0kubun <[email protected]>
2023-08-13[DOC] Don't suppress autolinksBurdetteLamar
Notes: Merged: https://github.com/ruby/ruby/pull/8215
2023-06-28[DOC] Fixes for link fragments (#7981)Burdette Lamar
Notes: Merged-By: peterzhu2118 <[email protected]>
2023-05-29Unify error messages of rb_num2ulong and rb_num2ullPeter Zhu
The error messages were slightly different due, which causes different behaviour on 32-bit and 64-bit systems. Notes: Merged: https://github.com/ruby/ruby/pull/7872
2023-04-06[Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec Notes: Merged: https://github.com/ruby/ruby/pull/7393
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar