aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
Commit message (Collapse)AuthorAgeFilesLines
* bignum.c: avoid use of uninitialized value in Integer.sqrtrhe2017-11-021-0/+1
| | | | | | | | 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
* Get rid of shadowing local variablesnobu2017-10-181-2/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: use NUM2DBLnobu2017-09-221-1/+1
| | | | | | | | * 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
* bignum.c: fix inexact estimationnobu2017-04-151-0/+3
| | | | | | | | * 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
* bignum.c: [DOC] typos and grammarstomar2017-03-161-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* bignum.c: rb_int_parse_cstrnobu2017-03-161-8/+31
| | | | | | | * 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
* revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]shyouhei2017-03-091-2/+4
| | | | | | | | | 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
* Use ADD instead of MULnaruse2017-03-071-10/+0
| | | | | | | | | | | | | | | | * 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
* optimize FIXABLE macroshyouhei2017-03-061-4/+12
| | | | | | | | | | | | 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
* Makefile.sub: ULL_TO_DOUBLEnobu2017-02-281-2/+8
| | | | | | | | | | | | * 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
* bignum.c: use predefined IDsnobu2017-02-251-6/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* bignum.c: improve estimatenobu2017-02-251-23/+35
| | | | | | | * 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
* bignum.c (bary_zero_p): constifynobu2017-02-251-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* extract initial sqrt estimation [Feature #13219]nobu2017-02-241-18/+28
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Integer.sqrt [Feature #13219]nobu2017-02-241-3/+64
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* bignum.c: NAIVE_MUL_DIGITSnobu2017-02-231-15/+8
| | | | | | | * 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
* bignum.c: unnecessary checknobu2017-01-071-3/+0
| | | | | | | * 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
* bignum.c: fix rb_cstr_parse_inum endpnobu2017-01-051-0/+1
| | | | | | | * 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
* bignum.c: precise fdivnobu2016-12-251-0/+2
| | | | | | * 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
* bignum.c (DBL_BIGDIG): make enumnobu2016-12-251-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ruby.h: rb_big_signnobu2016-11-191-0/+6
| | | | | | | * 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
* rational.c: avoid needless object allocation with nurat_to_doublemrkn2016-11-111-11/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* bignum.c: use RB_INTEGER_TYPE_Pnobu2016-11-011-5/+5
| | | | | | | | * 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
* [DOC] replace Fixnum with Integer [ci skip]nobu2016-10-261-2/+2
| | | | | | * 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
* * internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.usa2016-10-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | 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
* deprecate Fixnum and Bignumnobu2016-09-191-0/+1
| | | | | | | | * 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
* * bignum.c (rb_big2ulong): the old logic seems to try to avoidnaruse2016-06-281-16/+8
| | | | | | | | | | | | | | | 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
* Integer unification macronobu2016-06-131-0/+4
| | | | | | | | | | | * 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
* [Feature #12005] Unify Fixnum and Bignum into Integerakr2016-05-171-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * [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
* [DOC]akr2016-04-301-26/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Define Integer#/ instead of Bignum#/.akr2016-04-301-10/+0
| | | | | | | | | | | | * 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
* Define Integer#+ instead of Bignum#+.akr2016-04-301-8/+0
| | | | | | | | | | * 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
* Define Integer#- instead of Bignum#-.akr2016-04-301-8/+0
| | | | | | | | | | * 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
* Define Integer#* instead of Bignum#*.akr2016-04-301-8/+0
| | | | | | | | | | * 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
* Define Integer#% instead of Bignum#%.akr2016-04-301-1/+0
| | | | | | | | | | * 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
* Define Integer#== instead of Bignum#==.akr2016-04-301-1/+0
| | | | | | | | | | * 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
* Define Integer#> instead of Bignum#>.akr2016-04-301-11/+2
| | | | | | | | | | | | | * 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
* Define Integer#>= instead of Bignum#>=.akr2016-04-301-11/+2
| | | | | | | | | | | | | * 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
* Define Integer#< instead of Bignum#<.akr2016-04-301-11/+2
| | | | | | | | | | | | | * 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
* Define Integer#<= instead of Bignum#<=.akr2016-04-301-11/+2
| | | | | | | | | | | | | * 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
* Define Integer#GMP_VERSION.akr2016-04-301-0/+1
| | | | | | | * 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
* Define Integer#remainder instead of Bignum#remainder.akr2016-04-301-11/+1
| | | | | | | | | | | | | * 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
* {Fixnum,Bignum}#-@ is unified into Integer.akr2016-04-301-8/+0
| | | | | | | | | | | * 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
* {Fixnum,Bignum}#div is unified into Integer.akr2016-04-301-8/+0
| | | | | | | | | | | * 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
* {Fixnum,Bignum}#modulo is unified into Integer.akr2016-04-301-10/+0
| | | | | | | | | | | * 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
* {Fixnum,Bignum}#divmod is unified into Integer.akr2016-04-301-8/+0
| | | | | | | | | | | * 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
* {Fixnum,Bignum}#fdiv is unified into Integer.akr2016-04-301-14/+0
| | | | | | | | | | | * 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
* {Fixnum,Bignum}#** is unified into Integer.akr2016-04-301-14/+0
| | | | | | | | | | | * 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
* Rename fix_rev and rb_big_neg to fix_comp and rb_big_comp.akr2016-04-301-1/+1
| | | | | | | | | | * 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
* {Fixnum,Bignum}#~ is unified into Integer.akr2016-04-301-14/+1
| | | | | | | | | | | | | * 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