925 Commits

Author SHA1 Message Date
BurdetteLamar
2d01406644 [DOC] Harmonize rb_div methods 2025-12-16 17:47:08 -05:00
BurdetteLamar
cfd41cbf03 [DOC] Harmonize #-@ methods 2025-12-15 17:28:35 -05:00
BurdetteLamar
acbf55f4e6 [DOC] Harmonize #- methods 2025-12-15 17:27:54 -05:00
BurdetteLamar
7fbf321d23 [DOC] Harmonize #** methods 2025-12-15 17:27:24 -05:00
Peter Zhu
3e5c4ebe4b [DOC] Fix backticks in Numeric#ceil 2025-12-14 13:37:36 -05:00
Peter Zhu
cd27337d0b [DOC] Fix backticks in Numeric#floor 2025-12-14 13:37:36 -05:00
Peter Zhu
55ea3ec00f Fix strict aliasing warning in rb_int128_to_numeric
If we don't have uint128, then rb_int128_to_numeric emits a strict
aliasing warning:

    numeric.c:3641:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    3641 |         return rb_uint128_to_numeric(*(rb_uint128_t*)&n);
         |                                       ^~~~~~~~~~~~~~~~~
2025-12-08 15:01:05 -08:00
Samuel Williams
a7dc53b91c
Add support for u128, U128, s128 and S128 integers to IO::Buffer. (#15399) 2025-12-06 15:55:32 +13:00
Burdette Lamar
6e723bee45
[DOC] About Float Imprecision (#15293) 2025-12-02 21:41:21 -05:00
Burdette Lamar
b2f110651c
[DOC] Harmonize #+ methods 2025-12-02 21:39:25 -05:00
BurdetteLamar
688350dacc [DOC] Avoid term 'derived'; use 'subclass' 2025-11-28 17:24:13 -08:00
BurdetteLamar
7789aaca37 [DOC] Tweaks for Integer#** 2025-11-21 14:16:33 -08:00
BurdetteLamar
b47b37c12c [DOC] Harmonize #* methods 2025-11-21 14:11:54 -08:00
BurdetteLamar
826e91a7e2 [DOC] Harmonize mod methods 2025-11-20 14:06:41 -08:00
Nobuyoshi Nakada
cdb9893c55 Win32: Drop support for older than MSVC 8.0/_MSC_VER 1400
Visual C++ 2005 (8.0):
- _MSC_VER: 1400
- MSVCRT_VERSION: 80
2025-11-19 11:03:42 +09:00
tomoya ishida
f4f728b319
[Bug #21680] Fix (base**power_of_two).digits(base) bug (#15144)
Fix wrong condition in base multiplying loop.
2025-11-12 13:58:38 +09:00
Nobuyoshi Nakada
61df125325
[DOC] Markup code in Float::MIN document 2025-09-16 00:13:37 +09:00
tomoya ishida
a66e4f2154
Improve performance of bignum[beg, len] (#14007)
Implement rb_big_aref2.
Taking a small slice from large bignum was slow in rb_int_aref2.
2025-07-29 16:34:13 +00:00
Yusuke Endoh
3a7b9ca93b Fix Integer.sqrt to never exceed actual value
`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]
2025-04-07 11:08:10 +09:00
Nobuyoshi Nakada
9394d2084c
[DOC] Fix indentation
Not to make preceding paragraphs a code block.
2025-02-27 13:00:34 +09:00
Nobuyoshi Nakada
e433e6515e
[DOC] Exclude 'Class' and 'Module' from RDoc's autolinking 2025-01-02 12:36:06 +09:00
Nobuyoshi Nakada
b4ec22fe6c
[DOC] Exclude 'Method' from RDoc's autolinking 2025-01-02 12:23:49 +09:00
BurdetteLamar
9715131c32 [DOC] Fix example in Numeric#to_int 2024-12-17 13:01:39 -05:00
BurdetteLamar
d588a1c880 Correct order of listed methods 2024-12-02 15:28:53 -05:00
Takashi Kokubun
0f3723c644
Rewrite Numeric#dup and Numeric#+@ in Ruby (#11933) 2024-10-22 11:01:29 -07:00
Nobuyoshi Nakada
66b69d4ea5
[DOC] Move each Float#to_s example item by item
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-10-07 18:22:19 +09:00
BurdetteLamar
5df574d26e [DOC] Fix links 2024-09-10 14:04:41 -04:00
Peter Zhu
a7167d0cee Fix ceil when ndigits is large
[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.
2024-07-30 08:21:28 -04:00
Peter Zhu
3af2a7fbe1 Fix floor when ndigits is large
[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.
2024-07-30 08:21:28 -04:00
Aaron Patterson
2c1655314a Revert moving things to Ruby
This is slowing down benchmarks on x86, so lets revert it for now.
2024-07-29 14:18:11 -07:00
BurdetteLamar
aaa542d894 Doc for some #ceil and #floor 2024-07-26 11:22:18 -04:00
BurdetteLamar
78f1b835a0 Doc for some #ceil and #floor 2024-07-26 11:22:18 -04:00
Burdette Lamar
30b9912bb7
[DOC] Doc for Float#ceil (#11125) 2024-07-09 09:43:07 -04:00
Peter Zhu
ab3fa8dece [DOC] Use backticks instead of HTML tags 2024-07-09 08:55:58 -04:00
Peter Zhu
5de6d0b35f [DOC] Fix granularity calculation
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-09 08:55:58 -04:00
BurdetteLamar
a57b4340d0 Doc fixes 2024-07-08 14:35:29 -04:00
Burdette Lamar
f5dfadf38b
[DOC] Doc for Integer#floor (#11077) 2024-07-03 16:00:00 -04:00
Aaron Patterson
f4b313f733 move Integer#downto to Ruby
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-07-03 10:01:41 -07:00
BurdetteLamar
9930647134 Doc for Integer#ceil 2024-06-29 10:33:54 -04:00
Artur
dd578cf2f1
[DOC] Enhance Numeric#nonzero? doc
Add `zero?` as a related method
2024-04-26 12:33:41 +00:00
Reznov
19f4b06b9d
Reducing the number of divisions in rb_fix_digits 2024-04-08 12:51:32 +09:00
Peter Zhu
9ad175c1ee Register rb_fix_to_s_static as global right after creating
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-27 09:39:23 -04:00
tompng
0ff2c7fe6f Faster Integer.sqrt for large bignum
Integer.sqrt uses Newton's method.
This pull request reduces the precision which was unnecessarily high in each calculation step.
2024-03-18 13:52:27 +09:00
Jean Boussier
d4f3dcf4df Refactor VM root modules
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-03-06 15:33:43 -05:00
Nobuyoshi Nakada
3dccb716da
Use defined?(yield) and SIZED_ENUMERATOR
Prefer built-in features over method calls that may be overridden.
2024-02-17 23:28:00 +09:00
Yusuke Endoh
25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Peter Zhu
fd87259a26 Replace assert with RUBY_ASSERT in numeric.c
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-02-12 15:07:47 -05:00
BurdetteLamar
8cad6fc90a Tweak to Integer What's Here 2024-01-06 13:25:17 -05:00
BurdetteLamar
4a44bf8c34 Tweak to Float What's Here 2024-01-06 13:24:48 -05:00
BurdetteLamar
7b615bfdf3 Tweak to Float What's Here 2024-01-06 13:24:48 -05:00