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

764 Коммитов

Автор SHA1 Сообщение Дата
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
mrkn d611a7c77b rational.c: optimize Rational#==
* rational.c (nurat_eqeq_p): optimize Rational#==.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_equal): rename from int_equal and remove static
  to be exported.

* internal.h (rb_int_equal): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 02:24:32 +00:00
mrkn fb40c3776a rational.c: optimize Rational#<=>
* rational.c (nurat_cmp): optimize Rational#<=>.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_int_cmp): rename from int_cmp and remove static
  to be exported.

* internal.h (rb_int_cmp): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 01:29:01 +00:00
mrkn d8769bffe5 rational.c: optimize Rational#**
* rational.c (nurat_expt): optimize Rational#**.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

* numeric.c (rb_float_pow): rename flo_pow() to rb_float_pow()
  and remove static to be exporetd.

* internal.h (rb_int_pow, rb_float_pow): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 16:38:28 +00:00
mrkn 06d701a1f0 rational.c: avoid needless object allocation with nurat_to_double
* rational.c (nurat_to_double): introduce to convert rational to double
  without object allocation.

* rational.c (rb_rational_plus, nurat_{sub,mul,to_f}): rewrite by using
  nurat_to_double.

* bignum.c (rb_big_fdiv_double): introduce to calculate fdiv and return
  the result as a double value.

* bignum.c (big_fdiv{,_int,_float}): change the return types for
  implementing rb_big_fdiv_double.

* bignum.c (rb_big_fdiv): rewrite by using rb_big_fdiv_double.

* numeric.c (rb_int_fdiv_double): introduce to calculate fdiv and return
  the result as a double value.

* numeric.c (fix_fdiv_double): rewrite from fix_fdiv to return the
  result as a double value.

* numeric.c (rb_int_fdiv): rewrite by using rb_int_fdiv_double.

* internal.h (rb_{big,int}_fdiv_double): exported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 15:55:30 +00:00
mrkn f64a53462e numeric.c, rational.c: refactor by using FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P
* numeric.c (num_zero_p, fix_divide, fix_mod, fix_divmod): refactor by using
  FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P.

* rational.c (INT_NEGATIVE_P, INT_ZERO_P): ditto.

* internal.h: move FIXNUM_NEGATIVE_P and FIXNUM_ZERO_P from numeric.c

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 14:39:25 +00:00
mrkn c05cfe3739 numeric.c, internal.h: export int_fdiv() as rb_int_fdiv()
* numeric.c (rb_int_fdiv): export int_fdiv() as rb_int_fdiv().

* internal.h (rb_int_fdiv): add declaration of rb_int_fdiv().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-10 15:23:33 +00:00
ko1 75775157ea Introduce table improvement by Vladimir Makarov <vmakarov@redhat.com>.
[Feature #12142]
	See header of st.c for improvment details.

	You can see all of code history here:
	<https://github.com/vnmakarov/ruby/tree/hash_tables_with_open_addressing>

	This improvement is discussed at
	<https://bugs.ruby-lang.org/issues/12142>
	with many people, especially with Yura Sokolov.

	* st.c: improve st_table.

	* include/ruby/st.h: ditto.

	* internal.h, numeric.c, hash.c (rb_dbl_long_hash): extract a function.

	* ext/-test-/st/foreach/foreach.c: catch up this change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-07 00:45:00 +00:00
nobu 04ff7cf712 numeric.c: raise TypeError at wrong argument
* numeric.c (int_pos_p, int_neg_p): raise TypeError if not an
  Integer instead of returning nil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 15:45:42 +00:00
shugo a0842e7cd8 * numeric.c (rb_int_round): cast to SIGNED_VALUE to suppress
warnings by -Wsign-compare.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 15:02:17 +00:00
nobu dfe91fcd08 numeric.c: round to nearest even
* numeric.c (flo_round, int_round): support round-to-nearest-even
  semantics of IEEE 754 to match sprintf behavior, and add `half:`
  optional keyword argument for the old behavior.
  [ruby-core:76273] [Bug #12548]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 09:49:39 +00:00
mrkn 95e9ccbb6c numeric.c (rb_int_digits): Fix exception message
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-04 04:05:07 +00:00
nobu 13149a59d8 numeric.c: bit op with non-integer
* numeric.c (rb_num_coerce_bit): enable bit operations with
  coercing by non-integer object.  [ruby-core:77783] [Bug #12875]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-01 22:34:30 +00:00
nobu 69fc155c77 numeric.c: use rb_num_coerce_bit
* numeric.c (int_and, int_or, int_xor): use rb_num_coerce_bit to
  reduce repeated code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-01 13:10:14 +00:00
nobu cbfe54c560 numeric.c: fix return value on big 0
* numeric.c (num_zero_p): should return true if zero.
  rb_bigzero_p returns 1 or 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-01 12:35:32 +00:00
nobu 22e41718a4 numeric.c: adjust indent [ci skip]
* numeric.c (rb_num2ulong_internal): adjust indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-01 12:35:31 +00:00
nobu 5dc2472024 numeric.c: fix typos [ci skip]
* numeric.c (rb_num2ulong_internal, rb_num2ull): fix typos in
  comments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-01 12:35:30 +00:00
nobu 4e44f6ef86 [DOC] replace Fixnum with Integer [ci skip]
* numeric.c: [DOC] update document for Integer class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-26 06:11:23 +00:00
nobu bd3eb8afec numeric.c: fix up r55891
* numeric.c (num_funcall1): check recursion by inverse pair, to
  fix fake infinite recursion.  [ruby-core:77713] [Bug #12864]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-22 13:33:34 +00:00
usa c2dd2d268e * internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
a hash value of Object might be Bignum, but it causes many troubles
  expecially the Object is used as a key of a hash.  so I've gave up
  to do so.

* array.c (rb_ary_hash): use above macro.

* bignum.c (rb_big_hash): ditto.

* hash.c (rb_obj_hash, rb_hash_hash): ditto.

* numeric.c (rb_dbl_hash): ditto.

* proc.c (proc_hash): ditto.

* re.c (rb_reg_hash, match_hash): ditto.

* string.c (rb_str_hash_m): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-04 16:25:01 +00:00
nobu 91430022d6 numeric.c: adjust type
* numeric.c (rb_fix2str): cast to a pointer to adjust argument
  type for the format.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-02 03:32:07 +00:00
usa ae55ecc267 * numeric.c (rb_fix2str): detect unnormalized Fixnum value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-01 17:04:04 +00:00
nobu 0cc169d1de fid typos [ci skip]
* fix typos, "a" before "Integer" to "an".  [Fix GH-1438]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-24 02:28:25 +00:00
nobu 772fd010b6 deprecate Fixnum and Bignum
* numeric.c (Init_Numeric), bignum.c (Init_Bignum): deprecate
  Fixnum and Bignum.  this may be reverted after previews.
  [Feature #12739]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-19 08:05:26 +00:00
nobu ab65e9d983 numeric.c: round_to_nearest
* numeric.c (round_to_nearest): extract and reduce for platforms
  where round is not available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-15 01:59:58 +00:00
nobu ba1ef74f05 numeric.c: infinite recursion
* numeric.c (num_funcall0, num_funcall1): get rid of infinite
  recursion in fallback methods of Numeric.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-13 14:08:03 +00:00
mrkn 94468b4ea5 numeric.c, complex.c: Add finite? and infinite? consistent with Float
* numeric.c (num_finite_p, num_infinite_p): Add Numeric#finite? and
  Numeric#infinite?  [Feature #12039] [ruby-core:73618]

* complex.c (rb_complex_finite_p): Add Complex#finite?

* complex.c (rb_complex_infinite_p): Add Complex#infinite?

* test/ruby/test_bignum.rb: Add test for Integer#finite? and
  Integer#infinite?

* test/ruby/test_fixnum.rb: ditto.

* test/ruby/test_rational.rb: Add test for Rational#finite? and
  Rational#infinite?

* test/ruby/test_complex.rb: Add test for Complex#finite? and
  Complex#infinite?

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-17 14:53:00 +00:00
nobu 89ed4f41a3 complex.c: rb_complex prefix
* complex.c (rb_complex_plus, rb_complex_mul): rename to
  rb_complex prefix.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-12 13:17:04 +00:00
nobu 558b9d05b2 numeric.c: round as double
* numeric.c (flo_round): compare as double, not long double with
  i387.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-08 05:38:16 +00:00
nobu 9bb27fa318 numeric.c: round nearly middle value
* numeric.c (flo_round): [EXPERIMENTAL] adjust the case that the
  receiver is close to the exact but unrepresentable middle value
  of two values in the given precision.
  http://d.hatena.ne.jp/hnw/20160702

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-07 07:37:55 +00:00
nobu 6c9ffbf5b3 numeric.c: fix doc of Integer#digits [ci skip]
* numeric.c: [DOC] fix rdoc directive, and an example of negative
  value.  [ruby-core:76025] [Bug #12487]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-14 16:46:18 +00:00
mrkn 9042cf217e numeric.c: Add Integer#digits [Feature #12447] [ruby-core:75799]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-13 11:43:54 +00:00
nobu c071c05229 Integer unification macro
* include/ruby/ruby.h (RUBY_INTEGER_UNIFICATION): macro to tell if
  Integer is integrated.  [ruby-core:75718][Bug #12427]
* include/ruby/backward.h, internal.h (rb_cFixnum, rb_cBignum):
  fallback to rb_cInteger.
* bignum.c, numeric.c, ext/json/generator/generator.{c,h}: use the
  macro.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-13 11:34:56 +00:00
nobu 88cc25f96d missing.h: isfinite
* include/ruby/missing.h (isfinite): move from numeric.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-23 12:33:39 +00:00
nobu 4a9705d6e3 ruby.h: RB_INTEGER_TYPE_P
* include/ruby/ruby.h (RB_INTEGER_TYPE_P): new macro and
  underlying inline function to check if the object is an
  Integer (Fixnum or Bignum).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-18 01:17:43 +00:00
mrkn d5595a9627 Optimize enum_sum for a range from int to int
* enum.c (enum_sum): Optimize for a range from int to int.

* test/ruby/test_enum.rb (test_range_sum): Move from test_range.rb,
  and add assertions for some conditions.

* test/ruby/test_enum.rb (test_hash_sum): Move from test_hash.rb.

* test/ruby/test_hash.rb, test/ruby/test_range.rb: Remove test_sum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 15:08:33 +00:00
akr 449fbfd4d4 Use Integer instead of Fixnum and Bignum.
* object.c, numeric.c, enum.c, ext/-test-/bignum/mul.c,
  lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rexml/xpath_parser.rb,
  lib/rubygems/specification.rb, lib/uri/generic.rb,
  bootstraptest/test_eval.rb, basictest/test.rb,
  test/-ext-/bignum/test_big2str.rb, test/-ext-/bignum/test_div.rb,
  test/-ext-/bignum/test_mul.rb, test/-ext-/bignum/test_str2big.rb,
  test/csv/test_data_converters.rb, test/date/test_date.rb,
  test/json/test_json_generate.rb, test/minitest/test_minitest_mock.rb,
  test/openssl/test_cipher.rb, test/rexml/test_jaxen.rb,
  test/ruby/test_array.rb, test/ruby/test_basicinstructions.rb,
  test/ruby/test_bignum.rb, test/ruby/test_case.rb,
  test/ruby/test_class.rb, test/ruby/test_complex.rb,
  test/ruby/test_enum.rb, test/ruby/test_eval.rb,
  test/ruby/test_iseq.rb, test/ruby/test_literal.rb,
  test/ruby/test_math.rb, test/ruby/test_module.rb,
  test/ruby/test_numeric.rb, test/ruby/test_range.rb,
  test/ruby/test_rational.rb, test/ruby/test_refinement.rb,
  test/ruby/test_rubyvm.rb, test/ruby/test_struct.rb,
  test/ruby/test_variable.rb, test/rubygems/test_gem_specification.rb,
  test/thread/test_queue.rb: Use Integer instead of Fixnum and Bignum.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 13:15:57 +00:00
akr f9727c12cc [Feature #12005] Unify Fixnum and Bignum into Integer
* [Feature #12005] Unify Fixnum and Bignum into Integer

* include/ruby/ruby.h (rb_class_of): Return rb_cInteger for fixnums.

* insns.def (INTEGER_REDEFINED_OP_FLAG): Unified from
  FIXNUM_REDEFINED_OP_FLAG and BIGNUM_REDEFINED_OP_FLAG.

* vm_core.h: Ditto.

* vm_insnhelper.c (opt_eq_func): Use INTEGER_REDEFINED_OP_FLAG instead
  of FIXNUM_REDEFINED_OP_FLAG.

* vm.c (vm_redefinition_check_flag): Use rb_cInteger instead of
  rb_cFixnum and rb_cBignum.
  (C): Use Integer instead of Fixnum and Bignum.

* numeric.c (fix_succ): Removed.
  (Init_Numeric): Define Fixnum as Integer.

* bignum.c (bignew): Use rb_cInteger instead of Rb_cBignum.
  (rb_int_coerce): replaced from rb_big_coerce and return fixnums
  as-is.
  (Init_Bignum): Define Bignum as Integer.
  Don't define ===.

* error.c (builtin_class_name): Return "Integer" for fixnums.

* sprintf.c (ruby__sfvextra): Use rb_cInteger instead of rb_cFixnum.

* ext/-test-/testutil: New directory to test.
  Currently it provides utilities for fixnum and bignum.

* ext/json/generator/generator.c: Define mInteger_to_json.

* lib/mathn.rb (Fixnum#/): Redefinition removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 06:53:48 +00:00
nobu da696ae794 drop FreeBSD < 4 support
* NEWS: drop FreeBSD < 4 support.
  The most recent version affected by this is 3.5 and was released
  in 2000.
  https://www.freebsd.org/releases/3.5R/announce.html
  https://en.wikipedia.org/wiki/History_of_FreeBSD#Version_history

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-12 23:46:43 +00:00
naruse a6c8e8d15b * configure.in: add -Wsuggest-attribute=noreturn and suppress warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-08 00:55:28 +00:00
yui-knk 903161e0af numeric.c: Remove prototype declarations to internal.h
* numeric.c (fix_plus): Remove rb_nucomp_add prototype
  declaration.

* numeric.c (fix_mul): Remove rb_nucomp_mul prototype
  declaration.

* internal.h (rb_nucomp_add, rb_nucomp_mul): add prototype
  declarations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-04 14:12:10 +00:00
kazu 8ef6dacb24 Update result of 123456789 ** -2
* numeric.c: [DOC] Update result of 123456789 ** -2.
  [ruby-dev:49606] [Bug #12339]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-03 14:31:40 +00:00
kazu 77a99fd4d5 Update rdoc of Integer#modulo [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-02 11:46:02 +00:00
akr 396d835d09 [DOC] merge documents for {Integer,Fixnum}#succ.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-01 01:35:43 +00:00
akr c19c8ef4ae [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 13:05:22 +00:00
akr 6b6fa21031 Gather Fixnum method definitions.
* numeric.c (Init_Numeric): Gather Fixnum method definitions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 12:55:59 +00:00
akr 8248c26e6d Define Integer#/ instead of Bignum#/.
* numeric.c (rb_int_div): Define Integer#/.

* bignum.c (rb_big_div): Don't define Bignum#/.

* lib/mathn.rb (Integer#/): Replace Integer#/ instead of Bignum#/.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 12:39:53 +00:00
akr d0e2d150b8 Define Integer#+ instead of Bignum#+.
* numeric.c (rb_int_plus): Define Integer#+.

* bignum.c (rb_big_plus): Don't define Bignum#+.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 12:24:06 +00:00
akr 11ca96d3a3 Define Integer#- instead of Bignum#-.
* numeric.c (rb_int_minus): Define Integer#-.

* bignum.c (rb_big_minus): Don't define Bignum#-.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 12:09:31 +00:00
akr a9f3a1cda1 Define Integer#* instead of Bignum#*.
* numeric.c (rb_int_mul): Define Integer#*.

* bignum.c (rb_big_mul): Don't define Bignum#*.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 11:54:26 +00:00
akr e27a06f4bb Define Integer#% instead of Bignum#%.
* numeric.c (rb_int_modulo): Define Integer#%.

* bignum.c (rb_big_modulo): Don't define Bignum#%.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 11:31:28 +00:00
akr 25f2c85066 Define Integer#== instead of Bignum#==.
* numeric.c (int_equal): Define Integer#==.

* bignum.c (rb_big_eq): Don't define Bignum#==.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 11:18:00 +00:00
akr 70279a5700 Define Integer#> instead of Bignum#>.
* numeric.c (int_gt): Define Integer#>.

* bignum.c (rb_big_gt): Don't define Bignum#>.
  Renamed from big_gt.

* internal.h (rb_big_gt): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 10:42:06 +00:00
akr 289c3f40a1 Define Integer#>= instead of Bignum#>=.
* numeric.c (int_ge): Define Integer#>=.

* bignum.c (rb_big_ge): Don't define Bignum#>=.
  Renamed from big_ge.

* internal.h (rb_big_ge): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 10:26:17 +00:00
akr 6b16db9c80 Define Integer#< instead of Bignum#<.
* numeric.c (int_lt): Define Integer#<.

* bignum.c (rb_big_lt): Don't define Bignum#<.
  Renamed from big_lt.

* internal.h (rb_big_lt): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 10:10:23 +00:00
akr d00bca92a9 Define Integer#<= instead of Bignum#<=.
* numeric.c (int_le): Define Integer#<=.

* bignum.c (rb_big_le): Don't define Bignum#<=.
  Renamed from big_le.

* internal.h (rb_big_le): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 09:48:25 +00:00
akr 11678caa34 Define Integer#-@ instead of Fixnum#-@.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 08:52:49 +00:00
akr 635cff451f Define Integer#remainder instead of Bignum#remainder.
* numeric.c (int_remainder): Define Integer#remainder.

* bignum.c (rb_big_remainder): Don't define Bignum#remainder.

* internal.h (rb_big_remainder): Declared.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 08:27:30 +00:00
akr ae225a2ca8 {Fixnum,Bignum}#-@ is unified into Integer.
* numeric.c (rb_int_uminus): {Fixnum,Bignum}#-@ is unified into
  Integer.

* bignum.c (rb_big_uminus): Don't define Bignum#-@.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 06:30:08 +00:00
akr 73dd745cf1 {Fixnum,Bignum}#div is unified into Integer.
* numeric.c (rb_int_idiv): {Fixnum,Bignum}#div is unified into
  Integer.

* bignum.c (rb_big_idiv): Don't define Bignum#div.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 05:43:15 +00:00
akr 728333dcd3 {Fixnum,Bignum}#modulo is unified into Integer.
* numeric.c (rb_int_modulo): {Fixnum,Bignum}#modulo is unified into
  Integer.

* bignum.c (rb_big_modulo): Don't define Bignum#modulo.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 05:26:52 +00:00
akr 1b1a1ed6c8 {Fixnum,Bignum}#divmod is unified into Integer.
* numeric.c (int_divmod): {Fixnum,Bignum}#divmod is unified into
  Integer.

* bignum.c (rb_big_divmod): Don't define Bignum#divmod.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 05:05:54 +00:00
akr bda463c134 move Fixnum#/ document position.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 04:22:27 +00:00
akr 27f9556de9 {Fixnum,Bignum}#fdiv is unified into Integer.
* numeric.c (int_fdiv): {Fixnum,Bignum}#fdiv is unified into
  Integer.

* bignum.c (rb_big_fdiv): Don't define Bignum#fdiv.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 04:20:56 +00:00
akr 8a2df1ce3f {Fixnum,Bignum}#** is unified into Integer.
* numeric.c (rb_int_pow): {Fixnum,Bignum}#** is unified into
  Integer.

* bignum.c (rb_big_pow): Don't define Bignum#**.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 03:59:02 +00:00
akr d73b431e50 Rename fix_rev and rb_big_neg to fix_comp and rb_big_comp.
* bignum.c (rb_big_comp): Renamed from rb_big_neg.

* numeric.c (fix_comp): Renamed from fix_rev.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 03:30:53 +00:00
akr 10fb4e151d {Fixnum,Bignum}#~ is unified into Integer.
* numeric.c (int_comp): {Fixnum,Bignum}#~ is unified into
  Integer.

* bignum.c (rb_big_neg): Don't define Bignum#~.

* internal.h (rb_big_neg): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 03:27:20 +00:00
akr b296cacb12 {Fixnum,Bignum}#& is unified into Integer.
* numeric.c (int_and): {Fixnum,Bignum}#& is unified into
  Integer.

* bignum.c (rb_big_and): Don't define Bignum#|.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 03:08:53 +00:00
akr 44af023d44 {Fixnum,Bignum}#| is unified into Integer.
* numeric.c (int_or): {Fixnum,Bignum}#| is unified into
  Integer.

* bignum.c (rb_big_or): Don't define Bignum#|.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 02:54:14 +00:00
akr f949a95dab {Fixnum,Bignum}#^ is unified into Integer.
* numeric.c (int_xor): {Fixnum,Bignum}#^ is unified into
  Integer.

* bignum.c (rb_big_xor): Don't define Bignum#^.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 15:35:23 +00:00
akr c71e02bd07 [Doc] Add Document-method: directives.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 13:05:09 +00:00
kazu b530f58647 Update rdoc of Integer#[] (fix -> int)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 12:59:59 +00:00
akr 02107a91c8 [DOC] move rdoc comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 12:46:46 +00:00
akr d5a7299bca {Fixnum,Bignum}#[] is unified into Integer.
* numeric.c (int_aref): {Fixnum,Bignum}#[] is unified into
  Integer.

* bignum.c (rb_big_aref): Don't define Bignum#<<.

* internal.h (rb_big_aref): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-27 11:56:03 +00:00
akr 68c661b8e5 [DOC] update Integer#<< doc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 12:29:41 +00:00
akr 06ca50338b {Fixnum,Bignum}#<< is unified into Integer.
* numeric.c (rb_int_lshift): {Fixnum,Bignum}#<< is unified into
  Integer.

* bignum.c (rb_big_lshift): Don't define Bignum#<<.

* internal.h (rb_big_lshift): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 12:23:05 +00:00
akr 69fbb21c12 {Fixnum,Bignum}#>> is unified into Integer.
* numeric.c (rb_int_rshift): {Fixnum,Bignum}#>> is unified into
  Integer.

* bignum.c (rb_big_rshift): Don't define Bignum#>>.

* internal.h (rb_big_rshift): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 12:09:40 +00:00
akr 8f045eddb2 {Fixnum,Bignum}#size is unified into Integer.
* numeric.c (int_size): {Fixnum,Bignum}#size is unified into Integer.

* bignum.c (rb_big_size_m): Don't define Bignum#size.

* internal.h (rb_big_size_m): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 11:47:14 +00:00
akr bcc1796983 {Fixnum,Bignum}#bit_length is unified into Integer.
* numeric.c (rb_int_bit_length): {Fixnum,Bignum}#bit_length is
  unified into Integer.

* bignum.c (rb_big_bit_length): Don't define Bignum#bit_length.

* internal.h (rb_big_bit_length): Declared.

--This iine, and those below, will be ignored--

M    ChangeLog
M    bignum.c
M    internal.h
M    numeric.c


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 11:17:37 +00:00
akr 9368d7515b * numeric.c (int_abs): Integer#{abs,magnitude} moved from Fixnum and Bignum.
* internal.h (rb_big_abs): Declared.

* bignum.c (rb_big_abs): Don't define Bignum#{abs,magnitude}.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 10:59:27 +00:00
nobu 0a38e38aea numeric.c: numeric ndigits
* numeric.c (num_floor, num_ceil, num_truncate): add an optional
  parameter, digits, as well as Numeric#round.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-18 03:57:34 +00:00
nobu fe96a2495c numeric.c: flo_truncate
* numeric.c (flo_truncate): add an optional parameter, digits, as
  well as Float#round.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-18 03:56:33 +00:00
nobu 39f31b8c87 numeric.c: int_truncate
* numeric.c (int_truncate): add an optional parameter, digits, as
  well as Integer#round.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-18 03:55:33 +00:00
nobu ae4eb682db numeric.c: update doc [ci skip]
* numeric.c (int_to_i): [DOC] floor and ceil are no longer
  synonyms.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-18 02:38:37 +00:00
nobu c258535186 numeric.c: flo_ceil
* numeric.c (flo_ceil): add an optional parameter, digits, as
  well as Float#round.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 06:56:36 +00:00
nobu d56b277684 numeric.c: flo_floor
* numeric.c (flo_floor): add an optional parameter, digits, as
  well as Integer#floor.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 06:54:38 +00:00
nobu a1542d33ca numeric.c: int_ceil
* numeric.c (int_ceil): add an optional parameter, digits, as
  well as Integer#round.  [Feature #12245]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 06:50:24 +00:00
nobu 15558a8f57 numeric.c: int_floor
* numeric.c (int_floor): add an optional parameter, digits, as
  well as Integer#round.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 06:47:55 +00:00
nobu 1ea1d2e4a7 numeric.c: int_round_zero_p
* bignum.c (rb_big_size): add wrapper function of BIGSIZE and
  rename the method funtion with _m suffix.
* numeric.c (int_round_zero_p): extracted from rb_int_round.
  optimize for Bignum, and convert VALUE returned by Numeric#size
  to long.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 05:12:01 +00:00
nobu aaf0f51f46 numeric.c: float_invariant_round
* numeric.c (float_invariant_round): extracted from flo_round to
  be optimizer-friendly, e.g., tail-call optimization.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 02:41:24 +00:00
nobu b4c0aac4c8 numeric.c: dbl2ival no longer rounds
* numeric.c (flodivmod): round division if it is a finite number
  and module is required.
* numeric.c (dbl2ival): do not round here.
* numeric.c (flo_ceil): use dbl2ival.
* numeric.c (flo_round): round explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-03 00:34:31 +00:00
nobu 95813d475f numeric.c: move declaration [ci skip]
* numeric.c (fix_lshift, fix_rshift, flo_truncate): move forward
  declaration to the top.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-02 22:38:44 +00:00
nobu 9a686593c7 numeric.c: prefer rb_check_arity
* numeric.c (flo_round, int_to_s, int_round): use rb_check_arity
  instead of rb_scan_args for a simple optional argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-02 06:33:26 +00:00
kazu 0a41425ad4 * numeric.c (int_pos_p): fix typos.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-28 12:25:41 +00:00
nobu 23e5b482ca numeric.c: rb_int2str
* numeric.c (rb_int2str): conversion function to String for
  generic Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:55:14 +00:00
nobu e9dc649d66 numeric.c: rb_int_round
* numeric.c (rb_int_round): rounding function for generic
  Integers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:54:50 +00:00
nobu 79b209f19a numeric.c: basic arithmetic
* numeric.c (rb_int_{uminus,plus,minus,mul,idiv,modulo}): basic
  arithmetic functions for generic Integers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:54:16 +00:00
nobu ed47a0ec80 numeric.c: Fixnum predicts
* numeric.c (FIXNUM_{POSITIVE,NEGATIVE,ZERO}_P): predict macros
  only for Fixnum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-26 01:52:00 +00:00
naruse 51c4ffa45b * internal.h (rb_fix_divmod_fix): like r54213, use FIX2NUM only if
x == FIXNUM_MIN && y == -1. This must be a rare case and it is
  expected compiler to handle well.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-21 13:36:03 +00:00
naruse 148f1b9d57 * internal.h (DLONG): defined if long is 32bit (and LONG_LONG is 64bit;
but LONG_LONG is always defined as 64bit), or there's int128_t.

* internal.h (DL2NUM): defined if DLONG is defined.

* internal.h (rb_fix_mul_fix): defined for `Fixnum * Fixnum`.

* insns.def (opt_mul): use rb_fix_mul_fix().

* numeric.c (fix_mul): ditto.

* time.c (mul): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 11:10:43 +00:00
nobu be05c5798f numeric.c: optimize Fixnum<->Bignum comparisons
* numeric.c (fix_gt, fix_ge, fix_lt, fix_le): optimize comparisons
  Fixnum against Bignum by rb_big_cmp in inversed order without
  new Bignum instance.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 09:53:50 +00:00
nobu 448b4eb117 fix r54193
* numeric.c (fix_cmp): invert the result as the comarison is
  inverted.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 12:53:36 +00:00
naruse b01312ab97 * numeric.c (fix_cmp): use rb_big_cmp if x is Fixnum and y is Bignum.
rb_big_cmp handles such case smartly with big_norm.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 10:06:57 +00:00
mrkn 5a213ee2e2 * numeric.c (int_to_f): raise NotImplementedError when a receiver
class is unknown.

* test/-ext-/integer/test_my_integer.rb (test_my_integer_to_f): modify
  a test for the above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 09:43:35 +00:00
mrkn 81f65a9e05 * bignum.c (Bignum#<=>): remove it because they are unified with
Integer#<=>.

* numeric.c (Integer#<=>, Fixnum#<=>): move <=> method from Fixnum to
  Integer.

* numeric.c (int_cmp): add this method for Integer#<=>.

* test/-ext-/integer/test_my_integer.rb (test_my_integer_cmp): add a
  test to examine Integer#<=> for unknown subclasses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 09:28:12 +00:00
mrkn 0d076fe4b3 * bignum.c (rb_big_to_f, Bignum#to_f): removed them because they are
unified with int_to_f and Integer#to_f.

* numeric.c (int_to_f): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 15:02:45 +00:00
mrkn b60a7b43fe * numeric.c (int_to_f, fix_to_f): rename fix_to_f to int_to_f, and add
treatment for subclasses which don't have definitions of to_f method.

* numeric.c (Integer#to_f, Fixnum#to_f): move to_f method from Fixnum
  to Integer.

* ext/-test-/integer/my_integer.rb: define helper class for testing
  to_f method for a subclass of Integer.

* ext/-test-/integer/extconf.rb: ditto.

* ext/-test-/integer/init.c: ditto.

* test/-ext-/integer/test_my_integer.rb: examine to_f method for a
  subclass of Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 14:52:46 +00:00
mrkn 18d114eff2 * bignum.c (Bignum#eql?): remove its definition because it is unified
with Numeric#eql?.

* numeric.c (num_eql): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 13:11:09 +00:00
mrkn ad0b5ebc50 * bignum.c (rb_big_to_s, Bignum#to_s): remove its definition because
it is unified with Integer#to_s.

* numeric.c (int_to_s): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 12:57:40 +00:00
mrkn a22ff208e5 * numeric.c (int_to_s): Move from flo_to_s.
* numeric.c (Integer#to_s): Move from Fixnum#to_s.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 12:33:28 +00:00
mrkn 2169bea82e * numeric.c (fix_zero_p, fix_even_p, fix_odd_p): remove needless
functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 17:17:08 +00:00
mrkn 0a607bc8f8 * numeric.c (int_even_p): treat Fixnum and Bignum values directly.
I forgot include this commit in the previous one.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 17:15:33 +00:00
mrkn aa1ea07d37 * bignum.c (Bignum#even?, Bignum#odd?): remove definitions
because they are unified with Integer#even? and Integer#odd?.

* numeric.c (Fixnum#zero?, Fixnum#even?, Fixnum#odd?): remove
  definitions because they are unified with Numeric#zero?,
  Integer#even?, and Integer#odd?.

* numeric.c (num_zero_p, int_even_p, int_odd_p): treat Fixnum and
  Bignum values directly.

* test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless
  test case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 17:11:42 +00:00