375 Commits

Author SHA1 Message Date
Nobuyoshi Nakada
ac135260de
Fix unused-but-set-global warnings in clang-23 2026-06-25 15:40:27 +09:00
Nobuyoshi Nakada
09dacb9c3d
[Bug #22079] Fix Float#ceil and Float#floor edge cases 2026-05-23 16:12:01 +09:00
Nobuyoshi Nakada
97ec327efc
Refine rb_flo_round_by_rational
Use already broken down arguments.
2026-05-23 16:12:01 +09:00
Nobuyoshi Nakada
793f4c9572
[Bug #20697] Parse r suffix at Rational 2026-05-11 12:24:02 +09:00
Jean Boussier
e4667e5109 Refactor NEWOB_OF for the common protected use case
Almost every objects are now WB protected, with just a few
exceptions, hence we can provide a much simpler interface.

It's also much easier to find the remaining unprotected objects.
2026-04-28 11:11:29 +09:00
Jean Boussier
c202bc08e1 Simplify NEWOBJ_OF and introduce EC_NEWOBJ_OF
We only very rarely have the execution context available, so
it's preferable to provide a simpler default macro.
2026-04-28 11:11:29 +09:00
Jean Boussier
70451a4018 Get rid of RGENGC_WB_PROTECTED_RATIONAL
It has been the default for a very long time and there is no good reason to
disable it.
2026-04-28 09:39:07 +09:00
Nobuyoshi Nakada
f70f8338e3
Direct calls for specific numeric types in complex/rational 2026-02-18 11:12:29 +09:00
Jean Boussier
d066b9e01c Refactor type error to be more consistent
[Bug #21864]

Co-Authored-By:  Benoit Daloze <eregontp@gmail.com>
2026-02-07 10:06:36 +01:00
Burdette Lamar
58fb95af36
[DOC] Harmonize #== methods (#15805) 2026-01-06 17:13:15 -05:00
Burdette Lamar
f98bbb7474
[DOC] Doc for Rational#<=> 2025-12-22 09:12:33 -05:00
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
Burdette Lamar
b2f110651c
[DOC] Harmonize #+ methods 2025-12-02 21:39:25 -05:00
BurdetteLamar
b47b37c12c [DOC] Harmonize #* methods 2025-11-21 14:11:54 -08:00
Burdette Lamar
14e75435ea
[DOC] Tweaks for String#to_r 2025-11-12 05:13:29 -05:00
Hartley McGuire
8120971932 Move more NilClass methods to ruby
```
$ make benchmark ITEM=nilclass COMPARE_RUBY="/opt/rubies/ruby-master/bin/ruby"
/opt/rubies/3.4.2/bin/ruby --disable=gems -rrubygems -I../benchmark/lib ../benchmark/benchmark-driver/exe/benchmark-driver \
                    --executables="compare-ruby::/opt/rubies/ruby-master/bin/ruby -I.ext/common --disable-gem" \
                    --executables="built-ruby::./miniruby -I../lib -I. -I.ext/common  ../tool/runruby.rb --extout=.ext  -- --disable-gems --disable-gem" \
                    --output=markdown --output-compare -v $(find ../benchmark -maxdepth 1 -name 'nilclass' -o -name '*nilclass*.yml' -o -name '*nilclass*.rb' | sort)
compare-ruby: ruby 3.5.0dev (2025-06-02T13:52:25Z master cbd49ecbbe) +PRISM [arm64-darwin24]
built-ruby: ruby 3.5.0dev (2025-06-02T22:47:21Z hm-ruby-nilclass 3e7f1f0466) +PRISM [arm64-darwin24]

|             |compare-ruby|built-ruby|
|:------------|-----------:|---------:|
|rationalize  |     24.056M|   53.908M|
|             |           -|     2.24x|
|to_c         |     23.652M|   82.781M|
|             |           -|     3.50x|
|to_i         |     89.526M|   84.388M|
|             |       1.06x|         -|
|to_f         |     84.746M|   96.899M|
|             |           -|     1.14x|
|to_r         |     25.107M|   83.472M|
|             |           -|     3.32x|
|splat        |     42.772M|   42.717M|
|             |       1.00x|         -|
```

This makes them much faster
2025-06-12 09:30:09 +02:00
Nobuyoshi Nakada
b4ec22fe6c
[DOC] Exclude 'Method' from RDoc's autolinking 2025-01-02 12:23:49 +09:00
Yusuke Endoh
45cd4a8296 Do not round a**b to infinity
... instead, just calculate the value unless it is too big.
Also, this change raises an ArgumentError if it is expected to exceed
16 GB in a 64-bit environment.

(It is possible to calculate it straightforward, but it would likely be
out-of-memory, so I didn't think it would make sense.)

[Feature #20811]
2024-11-08 19:48:56 +09:00
Nobuyoshi Nakada
f8e3dd4ec1
[Bug #20524] win32: Suppress GMP warning
```
C:\vcpkg\installed\x64-windows\include\gmp.h(2237): warning C4146: unary minus operator applied to unsigned type, result still unsigned
```
2024-06-05 18:01:28 +09:00
Jean Boussier
f06670c5a2 Eliminate usage of OBJ_FREEZE_RAW
Previously it would bypass the `FL_ABLE` check, but
since shapes introduction, it started having a different
behavior than `OBJ_FREEZE`, as it would onyl set the `FL_FREEZE`
flag, but not update the shape.

I have no indication of this causing a bug yet, but it seems
like a trap waiting to happen.
2024-04-16 17:20:35 +02:00
Peter Zhu
9a2b692249 Replace assert with RUBY_ASSERT in rational.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
Matt Valentine-House
026321c5b9 [Feature #19474] Refactor NEWOBJ macros
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec
2023-04-06 11:07:16 +01:00
Burdette Lamar
1a8a24a633
[DOC] Enhanced RDoc for NilClass (#7500) 2023-03-13 12:55:59 -04:00
BurdetteLamar
3b239d2480 Remove (newly unneeded) remarks about aliases 2023-02-19 14:26:34 -08:00
S-H-GAMELINKS
1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
S.H
c6f439a6a8
Improve performance some Integer and Float methods [Feature #19085] (#6638)
* Improve some Integer and Float methods

* Using alias and Remove unnecessary code

* Remove commentout code
2022-10-27 09:13:16 -07:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada
a080651f46
Disable GMP by -DUSE_GMP=0 2022-05-20 19:05:35 +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
Burdette Lamar
28fb6d6b9e
Adding links to literals and Kernel (#5192)
* Adding links to literals and Kernel
2021-12-03 07:12:28 -06:00
S-H-GAMELINKS
032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
Nobuyoshi Nakada
137fde717b
Make internal predicate functions to return simple boolean 2021-09-02 17:43:10 +09:00
S-H-GAMELINKS
a826747ade Remove unneeded comments in rational.c 2021-08-31 20:57:33 +09:00
Nobuyoshi Nakada
04be8e84db
Use C99-defined macros to classify a floating-point number 2021-08-27 12:41:30 +09:00
S.H
58bd943436
Replace f_boolcast with RBOOL macro
* Move f_boolcast definination

* Remove f_boolcast macro defination

* to
2021-08-18 02:25:19 +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
Nobuyoshi Nakada
6329da588b Use predefined IDs 2021-07-27 15:40:27 +09:00
卜部昌平
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