summaryrefslogtreecommitdiff
path: root/bignum.c
AgeCommit message (Collapse)Author
2017-09-22numeric.c: use NUM2DBLnobu
* 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-04-15bignum.c: fix inexact estimationnobu
* 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-03-16bignum.c: [DOC] typos and grammarstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16bignum.c: rb_int_parse_cstrnobu
* 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-09revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]shyouhei
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-07Use ADD instead of MULnaruse
* 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-06optimize FIXABLE macroshyouhei
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-02-28Makefile.sub: ULL_TO_DOUBLEnobu
* 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-25bignum.c: use predefined IDsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-25bignum.c: improve estimatenobu
* 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-25bignum.c (bary_zero_p): constifynobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-24extract initial sqrt estimation [Feature #13219]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-24Integer.sqrt [Feature #13219]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-23bignum.c: NAIVE_MUL_DIGITSnobu
* 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-01-07bignum.c: unnecessary checknobu
* 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-05bignum.c: fix rb_cstr_parse_inum endpnobu
* 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
2016-12-25bignum.c: precise fdivnobu
* 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-25bignum.c (DBL_BIGDIG): make enumnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-19ruby.h: rb_big_signnobu
* 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-11rational.c: avoid needless object allocation with nurat_to_doublemrkn
* 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-01bignum.c: use RB_INTEGER_TYPE_Pnobu
* 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-10-26[DOC] replace Fixnum with Integer [ci skip]nobu
* 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-04* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.usa
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-09-19deprecate Fixnum and Bignumnobu
* 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-06-28* bignum.c (rb_big2ulong): the old logic seems to try to avoidnaruse
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-13Integer unification macronobu
* 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-05-17[Feature #12005] Unify Fixnum and Bignum into Integerakr
* [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-04-30[DOC]akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-30Define Integer#/ instead of Bignum#/.akr
* 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-30Define Integer#+ instead of Bignum#+.akr
* 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-30Define Integer#- instead of Bignum#-.akr
* 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-30Define Integer#* instead of Bignum#*.akr
* 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-30Define Integer#% instead of Bignum#%.akr
* 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-30Define Integer#== instead of Bignum#==.akr
* 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-30Define Integer#> instead of Bignum#>.akr
* 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-30Define Integer#>= instead of Bignum#>=.akr
* 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-30Define Integer#< instead of Bignum#<.akr
* 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-30Define Integer#<= instead of Bignum#<=.akr
* 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-30Define Integer#GMP_VERSION.akr
* 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-30Define Integer#remainder instead of Bignum#remainder.akr
* 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{Fixnum,Bignum}#-@ is unified into Integer.akr
* 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{Fixnum,Bignum}#div is unified into Integer.akr
* 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{Fixnum,Bignum}#modulo is unified into Integer.akr
* 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{Fixnum,Bignum}#divmod is unified into Integer.akr
* 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{Fixnum,Bignum}#fdiv is unified into Integer.akr
* 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{Fixnum,Bignum}#** is unified into Integer.akr
* 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-30Rename fix_rev and rb_big_neg to fix_comp and rb_big_comp.akr
* 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{Fixnum,Bignum}#~ is unified into Integer.akr
* 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{Fixnum,Bignum}#& is unified into Integer.akr
* 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{Fixnum,Bignum}#| is unified into Integer.akr
* 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