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

321 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada c0dc717c45 [Bug #19087] Disallow successive underscores in Complex string 2022-12-02 01:35:45 +09: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
Nobuyoshi Nakada 86450d03a8 Reduce type check of arguments at Complex creation 2022-10-23 16:44:43 +09:00
Stephen Ierodiaconou 54cad3123a
[Bug #19004] `Complex.polar` handles complex singular `abs` argument
`Complex.polar` accepts Complex values as arguments for the polar form as long
as the value of the complex has no imaginary part (ie it is 'real'). In
`f_complex_polar` this is handled by extracting the real part of the arguments.
However in the case `polar` is called with only a single argument, the absolute
value (abs), then the Complex is created without applying a check on the type
of abs, meaning it is possible to create a Complex where the real part is itself
an instance of a Complex. This change removes the short circuit for the single
argument case meaning the real part extraction is performed correctly
(by f_complex_polar).

Also adds an example to `spec/ruby/core/complex/polar_spec.rb` to check that
the real part of a complex argument is correctly extracted and used in the
resulting Complex real and imaginary parts.
2022-10-23 12:59:06 +09:00
Nobuyoshi Nakada 7cf37a5722
[DOC] Add the polar form in String#to_c 2022-10-17 12:02:34 +09:00
Nobuyoshi Nakada b5cf356447 Consider Complex from Complex cases
The assertions that "an argument of a Complex constructor must not be
a Complex" may not hold for some Numeric objects.
2022-09-02 14:33:23 +09:00
Nobuyoshi Nakada 9212d96307 [Bug #18937] Coerce non-real non-Numeric into Complex at comparisons 2022-09-02 14:33:23 +09:00
Nobuyoshi Nakada a9b59e24f4 Turn `f_zero_p` to `bool` 2022-09-02 14:33:23 +09:00
Nobuyoshi Nakada d5f50463c2
[Bug #18937] Coerce non-Numeric into Complex at comparisons 2022-08-22 12:26:43 +09:00
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
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
Nobuyoshi Nakada 59bec48e48
Remove declarations unused since a95262356e 2021-10-18 23:46:58 +09:00
S.H b8c3a84bdd
Refactor and Using RBOOL macro 2021-09-15 08:11:05 +09:00
S-H-GAMELINKS 032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
卜部昌平 0375f1fe97 include/ruby/internal/intern/complex.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
S-H-GAMELINKS 250b86bbee Remove unneeded comment 2021-09-03 13:20:55 +09:00
Nobuyoshi Nakada a95262356e Extract always_finite_type_p and handle flonum cases 2021-09-02 23:11:33 +09:00
Nobuyoshi Nakada 137fde717b
Make internal predicate functions to return simple boolean 2021-09-02 17:43:10 +09:00
S-H-GAMELINKS d1d76f2428 Refactor f_infinite_p function 2021-09-02 17:39:22 +09:00
Nobuyoshi Nakada 80c1faf076
Use C99-defined signbit macro 2021-08-27 12:42:23 +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
Nobuyoshi Nakada 63663bb459
Rename nucomp_false s nucomp_real_p_m 2021-05-20 14:31:49 +09:00
卜部昌平 cc0dc67bbb cdhash_cmp: can also take complex
There are complex literals `123i`, which can also be a case condition.
2021-05-12 10:30:46 +09:00
S-H-GAMELINKS cc281bd7ac Remove duplicated float_arg defination 2021-03-19 07:07:23 +09:00
Nobuyoshi Nakada 184e82e8f0
Follow the NDEBUG given to the whole 2021-01-07 16:52:10 +09:00
Nobuyoshi Nakada b958e2add8 Removed canonicalization for mathn 2020-11-10 11:14:15 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Kenta Murata 68b5f14d53
Fix assertion failed in Complex.polar without NDEBUG (#3551)
Fixes [Bug #17172].
2020-09-16 19:27:16 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons.  We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
2020-08-15 12:09:26 +09:00
Jeremy Evans 98286e9850 Ensure origins for all included, prepended, and refined modules
This fixes various issues when a module is included in or prepended
to a module or class, and then refined, or refined and then included
or prepended to a module or class.

Implement by renaming ensure_origin to rb_ensure_origin, making it
non-static, and calling it when refining a module.

Fix Module#initialize_copy to handle origins correctly.  Previously,
Module#initialize_copy did not handle origins correctly.  For example,
this code:

```ruby
module B; end
class A
  def b; 2 end
  prepend B
end
a = A.dup.new
class A
  def b; 1 end
end
p a.b
```

Printed 1 instead of 2.  This is because the super chain for
a.singleton_class was:

```
a.singleton_class
A.dup
B(iclass)
B(iclass origin)
A(origin) # not A.dup(origin)
```

The B iclasses would not be modified, so the includer entry would be
still be set to A and not A.dup.

This modifies things so that if the class/module has an origin,
all iclasses between the class/module and the origin are duplicated
and have the correct includer entry set, and the correct origin
is created.

This requires other changes to make sure all tests still pass:

* rb_undef_methods_from doesn't automatically handle classes with
  origins, so pass it the origin for Comparable when undefing
  methods in Complex. This fixed a failure in the Complex tests.

* When adding a method, the method cache was not cleared
  correctly if klass has an origin.  Clear the method cache for
  the klass before switching to the origin of klass.  This fixed
  failures in the autoload tests related to overridding require,
  without breaking the optimization tests.  Also clear the method
  cache for both the module and origin when removing a method.

* Module#include? is fixed to skip origin iclasses.

* Refinements are fixed to use the origin class of the module that
  has an origin.

* RCLASS_REFINED_BY_ANY is removed as it was only used in a single
  place and is no longer needed.

* Marshal#dump is fixed to skip iclass origins.

* rb_method_entry_make is fixed to handled overridden optimized
  methods for modules that have origins.

Fixes [Bug #16852]
2020-06-03 09:50:37 -07:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada e49ecaed57
Optimize sin/cos
GCC/Clang can optimize to calculate `sin(x)` and `cos(x)` at once,
when the both are closely called on the same argument.

Similar optimization is possible for `__sinpi(x)` and `__cospi(x)`
if available, which calculate arguments in radian, i.e.
`sin(x*M_PI)` and `cos(x*M_PI)` respectively.
2020-05-03 15:29:51 +09:00
卜部昌平 32623150cd reroute redefinition of NDEBUG
NDEBUG can be defined via a command-line argument.  Should take care of
such situations.
2020-04-21 13:07:19 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Kazuhiro NISHIYAMA 09e76e9828
Improve consistency of bool/true/false 2019-11-25 15:09:09 +09:00
Jeremy Evans 2e551356a7 Make Kernel#{Pathname,BigDecimal,Complex} return argument if given correct type
This is how Kernel#{Array,String,Float,Integer,Hash,Rational} work.
BigDecimal and Complex instances are always frozen, so this should
not cause backwards compatibility issues for those.  Pathname
instances are not frozen, so potentially this could cause backwards
compatibility issues by not returning a new object.

Based on a patch from Joshua Ballanco, some minor changes by me.

Fixes [Bug #7522]
2019-09-21 16:10:37 -07:00
Nobuyoshi Nakada d69ffa4d93
Expanded f_quo 2019-08-10 14:38:30 +09:00
Nobuyoshi Nakada 98c22c78e4
Expanded f_real_p 2019-08-10 14:22:43 +09:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
Nobuyoshi Nakada ca524bcd49
Expanded f_numerator 2019-07-16 08:15:05 +09:00
Nobuyoshi Nakada 34019a22eb
Expanded f_denominator 2019-07-16 07:59:30 +09:00
Nobuyoshi Nakada 5bd83909b9
Expand f_arg to use particular functions directly 2019-07-14 20:42:10 +09:00
Nobuyoshi Nakada 1464f7a149
Expand f_abs to use particular functions directly 2019-07-14 20:42:08 +09:00