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

752 Коммитов

Автор SHA1 Сообщение Дата
rhe fe6615b31d bignum.c: avoid use of uninitialized value in Integer.sqrt
This is a follow-up fix to r57713. estimate_initial_sqrt() didn't
initialize BDIGITs except the topmost two, letting Integer.sqrt return
wrong result in the fast path, such as for (1<<504).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-02 06:30:18 +00:00
nobu 20685cdc85 Get rid of shadowing local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 04:35:25 +00:00
nobu 24ef8ad190 numeric.c: use NUM2DBL
* numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use
  NUM2DBL on unknown object.  RFLOAT_VALUE is only appliicable to
  T_FLOAT object.  [ruby-core:82924] [Bug #13928]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-22 03:05:02 +00:00
nobu df76f366a7 bignum.c: fix inexact estimation
* bignum.c (estimate_initial_sqrt): estimated square root is
  inexact if it is not equal to its ceil, needs Newton's method.
  [ruby-core:80696] [Bug #13440]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-15 15:29:09 +00:00
stomar 0bb1a6cbe0 bignum.c: [DOC] typos and grammar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 20:58:58 +00:00
nobu 92e2a7048e bignum.c: rb_int_parse_cstr
* bignum.c (rb_int_parse_cstr): extend rb_cstr_parse_inum with
  flags.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 03:21:12 +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
naruse ac6f08df23 Use ADD instead of MUL
* On recent CPUs, 2-operand MUL's latency is 3 cycle but ADD is 1 cycle.
* clang Optimizes `MUL rax,2` into `ADD rax,rax` but gcc7 doesn't.
* LONG2FIX is compiled into `lea r14,[r15+r15*1+0x1]`; this is 1cycle
  and run in parallel if the branch prediction is correct.
* Note that old (RB_POSFIXABLE(f) && RB_NEGFIXABLE(f)) is usually uses
  following instructions.
  * movabs rax,0x4000000000000000
  * add    rax,rdi
  * js
  It needs large immediate and Macro-Fusion is not applied.
  ADD and JO is much smaller though it is also Macro-Fusion unfriendly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-07 03:35:47 +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 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 5732225102 bignum.c: use predefined IDs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-25 07:27:07 +00:00
nobu 4dcad25b23 bignum.c: improve estimate
* bignum.c (estimate_initial_sqrt, rb_big_isqrt): improve initial
  estimate by sqrt().  [ruby-core:79754] [Feature #13250]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-25 05:44:39 +00:00
nobu dab7aa22f7 bignum.c (bary_zero_p): constify
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-25 04:13:42 +00:00
nobu a67c94cf40 extract initial sqrt estimation [Feature #13219]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-24 23:31:07 +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 6feeda594e bignum.c: NAIVE_MUL_DIGITS
* bignum.c (NAIVE_MUL_DIGITS): share threshold for bary_sq_fast
  between bary_mul and bigsq.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-23 06:55:42 +00:00
nobu 4dbbcc48de bignum.c: unnecessary check
* bignum.c (rb_cstr_parse_inum): remove unnecessary check.
  successive sign is rejected by conv_digit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-07 08:31:03 +00:00
nobu 7ccae4d150 bignum.c: fix rb_cstr_parse_inum endp
* bignum.c (rb_cstr_parse_inum): stores the address of the first
  invalid character when str is too big or contains an underscore.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-05 07:27:18 +00:00
nobu c6eb59c439 bignum.c: precise fdiv
* bignum.c (big_fdiv): more precise calculation.  [ruby-dev:49915]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-25 08:47:22 +00:00
nobu 6335fc6fe3 bignum.c (DBL_BIGDIG): make enum
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-25 08:42:28 +00:00
nobu 6839d47eb8 ruby.h: rb_big_sign
* include/ruby/ruby.h (RBIGNUM_SIGN): use a wrapper function to
  return the sign bit, instead of comparing with 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-19 04:32:52 +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
nobu 8baad2d31c bignum.c: use RB_INTEGER_TYPE_P
* bignum.c (rb_big_and, rb_big_or, rb_big_xor): use dedicated
  macro RB_INTEGER_TYPE_P instead of combination of FIXNUM_P and
  RB_BIGNUM_TYPE_P.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-01 07:51:55 +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
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 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
naruse 236b5e9778 * bignum.c (rb_big2ulong): the old logic seems to try to avoid
calculating `-(long)(num-1)-1` if `num` is not LONG_MIN. (Note that
  `-LONG_MIN` may be larger than LONG_MAX) But C compilers can
  optimize it into single NEG instruction.
  Therefore those two conditions can be single if-body.

* bignum.c (rb_big2long): ditto.

* bignum.c (rb_big2ull): ditto.

* bignum.c (rb_big2ll): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-28 18:42:12 +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
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
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 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 d13774e23f Define Integer#GMP_VERSION.
* bignum.c (Init_Bignum): Define Integer#GMP_VERSION.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30 09:12:11 +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 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