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

676 Коммитов

Автор SHA1 Сообщение Дата
nobu 9f5a468cf9 numeric.c: fix for small number
* numeric.c (flo_floor, flo_ceil): should not return zero for small
  number.  [ruby-core:81394] [Bug #13599]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-27 01:26:31 +00:00
nobu 015d05c6e6 numeric.c: remove duplicate code
* numeric.c (flo_to_i): use dbl2ival and reduce duplicate code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-26 17:11:15 +00:00
nobu 7db534a20c vm_insnhelper.c: rb_eql_opt should call eql?
* vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and
  String, not #==.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 05:29:35 +00:00
stomar f495fe4fc0 make Integer#{round,floor,ceil,truncate} always return integer
* numeric.c (int_round): return integer (self) instead of float
  for Integer#round with positive ndigits argument, because
  conversion to float introduces errors for large integers.
* numeric.c (int_floor): ditto for Integer#floor.
* numeric.c (int_ceil): ditto for Integer#ceil.
* numeric.c (int_truncate): ditto for Integer#truncate.

* test/ruby/test_integer.rb: adjust test cases and add some more.

[ruby-core:80645] [Bug #13420]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-06 19:58:12 +00:00
stomar 5e58811bc8 numeric.c: remove mention of Bignum from docs
* numeric.c: [DOC] remove mention of Bignum from Integer#{+,-,*,/},
  the return type does not depend on magnitude anymore.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-06 07:18:49 +00:00
stomar f280556f73 numeric.c: revise docs
* numeric.c: [DOC] revise docs for Numeric, Integer, Float:
  * nodoc Numeric#singleton_method_added
  * mention that result for Integer#** might also be Complex
  * add / simplify / fix some examples
  * mention aliases
  * fix rdoc formatting, typos, grammar
  * clarifications and other improvements

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-06 07:17:41 +00:00
eregon 413cece5c9 no longer rescue exceptions of #coerce in Integer#step
* numeric.c (num_step_negative_p): no more error hiding.
* test/ruby/test_float.rb, test/ruby/test_numeric.rb:
  follow the change. [Feature #7688]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25 11:42:31 +00:00
eregon bc1827e882 no longer rescue exceptions in numeric comparison operations
* numeric.c (do_coerce): no more error hiding.
* test/ruby/test_numeric.rb: follow the change.
  [Feature #7688]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25 11:42:20 +00:00
nobu 0472578b26 ruby.h: check argc to rb_funcall
* include/ruby/ruby.h (rb_funcall): check if argc matches the
  number of variadic arguments, and replace with rb_funcallv.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-15 02:09:27 +00:00
mrkn 1b5acc876b array.c: Improve performance of Array#sort with float elements
* array.c (sort_2): improve performance of Array#sort with float elements.

* internal.h (cmp_opt_Float, cmp_opt_data): added for checking whether or not
  Float#<=> can be optimizable.

* numeric.c (rb_float_cmp): added for internal use.

* internal.h (rb_float_cmp): ditto.

[Bug #13340]
[ruby-dev:50023]
[Fix GH-1539]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-13 07:22:35 +00:00
stomar 1a0dbb9eaa numeric.c: improve docs for Float
* numeric.c: [DOC] mention possibly surprising behavior of
  Float#{floor,ceil,to_i,truncate} due to floating point arithmetic.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-09 13:28:11 +00:00
stomar 5f22cfcc30 improve docs for #truncate, #floor, and #ceil methods
* numeric.c: [DOC] improve and harmonize documentation
  for {Float,Integer,Numeric}#{truncate,floor,ceil}.
* rational.c: [DOC] ditto for Rational#{truncate,floor,ceil}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03 19:23:13 +00:00
stomar c76aac30f2 improve docs for #round methods
* numeric.c: [DOC] improve and harmonize documentation
  for {Float,Integer,Numeric}#round.
* rational.c: [DOC] ditto for Rational#round.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03 19:19:20 +00:00
nobu 50d6291d86 numeric.c: improves Integer#round rdoc [ci skip]
* numeric.c (int_round): [DOC] improves Integer#round documentation
  as well as Float#round.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-28 02:30:14 +00:00
nobu e014c8c4d8 numeric.c: improves Float#round rdoc [ci skip]
* numeric.c (flo_round): [DOC] improves Float#round documentation
  to better highlight the half keyword.  [Fix GH-1541]

Author:    Evan Brodie <brodie.evan@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-28 02:15:51 +00:00
shyouhei c56edb9a59 revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]
This commit is auto-generated using following command:

svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-09 02:31:23 +00:00
shyouhei b515528271 re-introduce __builtin_add_overflow
r57789 (74cdd89) was gradually "improve"d by naruse through r57793 to
r57806, resulted in reverting the efect of r57789 while retaining its
complexity.  I think the current situation is slightly worse than
before (same output complicated source code).

Here I introduce __builtin_add_overflow again, which (I think) is what
naruse wanted to do in r57793.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-08 04:50:22 +00:00
shyouhei 74cdd893eb optimize FIXABLE macro
Looking at the source code, FIXABLE tends to be just before LOING2FIX
to check applicability of that operation.  Why not try computing first
then check for overflow, which should be optimial.

I also tried the same thing for unsigned types but resulted in slower
execution.  It seems RB_POSFIXABLE() is fast enough on modern CPUs.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 11:14:05 +00:00
nobu 63f298b0c1 opt_eq_func refactor
* vm_insnhelper.c (opt_eq_func): method to dispatch is resolved by
  only the receiver's class, not including the argument class.
  even if basic operation is redefined, other class conditions
  never meet.  optimize Float and non-Float case, delegate to
  rb_float_equal directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 06:44:11 +00:00
akr 2f3ff53f86 [DOC] update doc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-02 23:36:13 +00:00
nobu 7def092804 Makefile.sub: ULL_TO_DOUBLE
* win32/Makefile.sub (config.h): define ULL_TO_DOUBLE for
  conversion from unsigned __int64 to double, which is not
  implemented in till Visual Studio.NET 2003, aka VC7.1.

* bignum.c (estimate_initial_sqrt): use ULL_TO_DOUBLE if defined.

* numeric.c (BDIGIT_DBL_TO_DOUBLE): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-28 02:58:12 +00:00
nobu 0e099878eb numeric.c: suppress warning
* numeric.c (DEFINE_INT_SQRT): suppress a type-limits warning
  where int is always smaller than double.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-28 01:10:38 +00:00
stomar c25ee9f13f Add rdoc for Integer.sqrt
* numeric.c (rb_int_s_isqrt): [DOC] add rdoc for Integer.sqrt.
  [ruby-core:79762] [Bug #13251]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-26 12:51:41 +00:00
nobu 8c44061928 Integer.sqrt argument check
* numeric.c (rb_int_s_isqrt): check if the argument is an integer.
  [Feature #13219]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-24 09:39:17 +00:00
nobu bdd6b995f9 Integer.sqrt [Feature #13219]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-24 08:36:16 +00:00
nobu 06010b2b05 rational.c: infinity in power
* rational.c (nurat_expt): return Infinity due to overflow.
  [ruby-core:79686] [Bug #13242]:

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 23:28:26 +00:00
nobu 31ef3124a9 numeric.c: Numeric#clone and #dup
* numeric.c (num_clone, num_dup): no longer raises TypeError,
  returns the receiver instead as well as Integer and Float.
  [ruby-core:79636] [Bug #13237]

* object.c (rb_immutable_obj_clone): immutable object clone with
  freeze optional keyword argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 02:02:11 +00:00
naruse 038ccbd112 Use carry flag to reduce instructions
NOTE:
(1) Fixnum's LSB is always 1.
    It means you can always run `x - 1` without overflow.
(2) Of course `z = x + (y-1)` may overflow.
    Now z's LSB is always 1, and the MSB of true result is also 1.
    You can get true result in long as `(1<<63)|(z>>1)`,
    and it equals to `(z<<63)|(z>>1)` == `ror(z)`.

GCC and Clang have __builtin_add_ovewflow:
* https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
* https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-02 15:54:51 +00:00
nobu 3c199bb700 numeric.c: short circuit optimization
* numeric.c (fix_mul): short circuit when multiplication of Bignum
  and 0 or 1 not to make a Bignum unnecessarily.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-10 12:18:21 +00:00
nobu f0f8234a26 numeric.c: short circuit
* numeric.c (int_pow): short circuit when y is 0, always return 1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-05 07:27:19 +00:00
nobu 1778ed59e7 numeric.c: reduce fdiv
* numeric.c (rb_int_fdiv_double): reduce first for more precise
  result.  [ruby-core:78886] [Bug #13078]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-28 04:40:58 +00:00
yui-knk ea6510b862 numeric.c: remove not used lines
* numeric.c (rb_num_get_rounding_option): remove not used
  lines. After r57130 these lines are never reached.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 13:26:16 +00:00
akr 7a4fe57adb [DOC] itemize values for half option of Float#round.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 05:26:35 +00:00
nobu 581b995c54 numeric.c: rdoc of half option [ci skip]
* numeric.c (flo_round): [DOC] mention half option.  [Bug #12548]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 01:29:58 +00:00
nobu 114d1751dc numeric.c: allow nil as rounding mode option
* numeric.c (rb_num_get_rounding_option): allow nil same as the
  default behavior, per [ruby-core:77961].  [Bug #12548]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21 01:29:57 +00:00
usa e12265dae7 get rid of a test failure with VC10.
* numeric.c (round_half_up, round_half_down): use `round` always because it's
  defined in this file even if doesn't exist.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-12 16:18:45 +00:00
mrkn 0cb1a2b812 numeric.c: fix exception message for nil rounding
* numeric.c (rb_num_get_rounding_option): fix exception message
  for the case of nil rounding mode.

* test_float.rb: add an assertion for the above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 12:54:19 +00:00
nobu 1e95f9da88 remove unnecessary variable
* st.c (do_hash): remove unnecessary variable and cast.

* hash.c, numeric.c, st.c: adjust style and indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 03:36:52 +00:00
nobu 631dde2572 round-down
* numeric.c (round_half_down, int_round_half_down): support
  round-down mode.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-25 06:28:00 +00:00
mrkn b920d9545c complex.c: optimize f_gt_p some cases
* complex.c (f_gt_p): optimize f_gt_p for specific types of arguments.

* internal.h (rb_int_gt, rb_float_gt, rb_rational_cmp): exported.

* numeric.c (rb_float_gt): rename from flo_gt and be exported.

* numeric.c (rb_int_gt): rename from int_gt and be exported.

* rational.c (rb_rational_cmp): rename from nurat_cmp and be exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-22 05:21:12 +00:00
nobu b2270a36e7 numeric.c: refine error message
* numeric.c (rb_num_get_rounding_option): refine error message at
  invalid rounding mode.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-21 02:17:29 +00:00
mrkn c151aa88a9 complex.c: optimize f_negate
* complex.c (f_negate): optimize for special numeric types.

* complex.c (nucomp_expt): use rb_int_uminus instead of f_negate for
  fixnum value.

* internal.h (rb_float_uminus, rb_rational_uminus): exported.

* numeric.c (rb_float_uminus): rename from flo_uminus.

* rational.c (rb_rational_uminus): rename from nurat_negate, and add
  assertion for the parameter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-18 15:17:19 +00:00
nobu 81ec47ea18 internal.h: round macros
* internal.h (ROUND_FUNC, ROUND_CALL): macros wrapping round
  functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-18 06:29:51 +00:00
usa 998d1c6c30 numeric.c: get rid of a compile error on mingw64
* numeric.c (rb_fix2str): typo.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-17 08:50:36 +00:00
mrkn affa0f845c complex.c: optimize Numeric#polar and Numeric#arg
* complex.c (numeric_polar): optimize for Integer, Float, and Rational.

* complex.c (numeric_arg): directly create the value of pi.

* complex.c (f_negative_p): optimize for Integer, Float, and Rational.

* rational.c (INT_NEGATIVE_P): move the definition into internal.h.

* internal.h (INT_NEGATIVE_P): ditto.

* numeric.c (rb_float_abs): rename from flo_abs and export to be used
  from other source files..

* internal.h (rb_float_abs): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-16 04:25:35 +00:00
nobu ffa371d9aa numeric.c: limit return value
* numeric.c (num_equal): limit return value to true or false,
  instead of the result of the other as-is.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-13 02:04:51 +00:00
mrkn bdd18a2c31 rational.c: optimize Integer#lcm
* rational.c (f_div, f_mul, f_abs): optimize Integer#lcm
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_abs): rename from int_abs to be exported.

* internal.h (rb_int_div, rb_int_abs): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 15:43:26 +00:00
mrkn f40607d15d rational.c: optimize Float#to_r
* rational.c (float_to_r): optimize Float#to_r.

* numeric.c (rb_int_lshift): exported.

* internal.h (rb_int_lshift): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 11:52:00 +00:00
mrkn 9bb3022475 rational.c: optimize Rational#{floor,ceil,round,truncate}
* rational.c (f_{expt10,round_common},nurat_{floor,ceil,round_half_{up,even}}):
  optimize Rational#{floor,ceil,round,truncate}.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_divmod): rename from int_divmod to be exported.

* numeric.c (rb_int_and): rename from int_and to be exported.

* intern.h (rb_int_{divmod,and}): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 06:45:11 +00:00
mrkn e5aa590637 rational.c: purge f_cmp
* rational.c (f_cmp, nurat_expt): purge f_cmp.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* rational.c (INT_POSITIVE_P): added.

* numeric.c (FIXNUM_POSITIVE_P): move the definition into internal.h.

* internal.h (FIXNUM_POSITIVE_P): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 06:07:24 +00:00