aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
Commit message (Collapse)AuthorAgeFilesLines
* [Doc] Add Document-method: directives.akr2016-04-271-0/+24
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Update rdoc of Integer#[] (fix -> int)kazu2016-04-271-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] move rdoc comments.akr2016-04-271-137/+151
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* {Fixnum,Bignum}#[] is unified into Integer.akr2016-04-271-15/+33
| | | | | | | | | | | | | * 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
* [DOC] update Integer#<< doc.akr2016-04-261-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* {Fixnum,Bignum}#<< is unified into Integer.akr2016-04-261-8/+20
| | | | | | | | | | | | | * 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
* {Fixnum,Bignum}#>> is unified into Integer.akr2016-04-261-8/+20
| | | | | | | | | | | | | * 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
* {Fixnum,Bignum}#size is unified into Integer.akr2016-04-261-4/+19
| | | | | | | | | | | | * 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
* {Fixnum,Bignum}#bit_length is unified into Integer.akr2016-04-261-7/+32
| | | | | | | | | | | | | | | | | | | * 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
* * numeric.c (int_abs): Integer#{abs,magnitude} moved from Fixnum and Bignum.akr2016-04-261-13/+24
| | | | | | | | | | * 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
* numeric.c: numeric ndigitsnobu2016-04-181-12/+12
| | | | | | | * 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
* numeric.c: flo_truncatenobu2016-04-181-10/+27
| | | | | | | * 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
* numeric.c: int_truncatenobu2016-04-181-2/+63
| | | | | | | * 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
* numeric.c: update doc [ci skip]nobu2016-04-181-1/+1
| | | | | | | * 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
* numeric.c: flo_ceilnobu2016-04-131-7/+39
| | | | | | | * 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
* numeric.c: flo_floornobu2016-04-131-6/+40
| | | | | | | * 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
* numeric.c: int_ceilnobu2016-04-131-1/+57
| | | | | | | * 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
* numeric.c: int_floornobu2016-04-131-1/+55
| | | | | | | * 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
* numeric.c: int_round_zero_pnobu2016-04-131-5/+21
| | | | | | | | | | * 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
* numeric.c: float_invariant_roundnobu2016-04-131-6/+16
| | | | | | | * 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
* numeric.c: dbl2ival no longer roundsnobu2016-04-031-10/+5
| | | | | | | | | | * 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
* numeric.c: move declaration [ci skip]nobu2016-04-021-5/+3
| | | | | | | * 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
* numeric.c: prefer rb_check_aritynobu2016-04-021-14/+8
| | | | | | | * 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
* * numeric.c (int_pos_p): fix typos.kazu2016-03-281-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: rb_int2strnobu2016-03-261-0/+5
| | | | | | | * 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
* numeric.c: rb_int_roundnobu2016-03-261-11/+37
| | | | | | | * 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
* numeric.c: basic arithmeticnobu2016-03-261-0/+73
| | | | | | | * 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
* numeric.c: Fixnum predictsnobu2016-03-261-2/+6
| | | | | | | * 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
* * internal.h (rb_fix_divmod_fix): like r54213, use FIX2NUM only ifnaruse2016-03-211-5/+5
| | | | | | | 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
* * internal.h (DLONG): defined if long is 32bit (and LONG_LONG is 64bit;naruse2016-03-201-26/+1
| | | | | | | | | | | | | | | | 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
* numeric.c: optimize Fixnum<->Bignum comparisonsnobu2016-03-201-4/+4
| | | | | | | | * 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
* fix r54193nobu2016-03-191-1/+6
| | | | | | | * 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
* * numeric.c (fix_cmp): use rb_big_cmp if x is Fixnum and y is Bignum.naruse2016-03-191-1/+1
| | | | | | 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
* * numeric.c (int_to_f): raise NotImplementedError when a receivermrkn2016-03-191-1/+1
| | | | | | | | | 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
* * bignum.c (Bignum#<=>): remove it because they are unified withmrkn2016-03-191-13/+28
| | | | | | | | | | | | | | 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
* * bignum.c (rb_big_to_f, Bignum#to_f): removed them because they aremrkn2016-03-181-1/+5
| | | | | | | | 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
* * numeric.c (int_to_f, fix_to_f): rename fix_to_f to int_to_f, and addmrkn2016-03-181-5/+10
| | | | | | | | | | | | | | | | | | | 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
* * bignum.c (Bignum#eql?): remove its definition because it is unifiedmrkn2016-03-181-1/+7
| | | | | | | | 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
* * bignum.c (rb_big_to_s, Bignum#to_s): remove its definition becausemrkn2016-03-181-1/+9
| | | | | | | | 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
* * numeric.c (int_to_s): Move from flo_to_s.mrkn2016-03-181-6/+5
| | | | | | * 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
* * numeric.c (fix_zero_p, fix_even_p, fix_odd_p): remove needlessmrkn2016-03-171-49/+0
| | | | | | functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * numeric.c (int_even_p): treat Fixnum and Bignum values directly.mrkn2016-03-171-1/+9
| | | | | | 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
* * bignum.c (Bignum#even?, Bignum#odd?): remove definitionsmrkn2016-03-171-5/+18
| | | | | | | | | | | | | | | | 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
* * numeric.c (num_step): use rb_equal for zero check. rb_num_coerce_cmpmame2016-03-171-1/+1
| | | | | | created an object which caused extra overhead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_inject): Implement the specialized code for sum ofakr2016-03-171-0/+6
| | | | | | | | | | | | integers including Bignums. * internal.h (rb_fix_plus): Declared to be usable from enum_inject. * numeric.c (rb_fix_plus): Defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * numeric.c (fix2str): improve r54092 like rb_int2big().naruse2016-03-141-11/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: fix edge casenobu2016-03-131-1/+9
| | | | | | | * numeric.c (rb_fix2str): fix edge case, accidentally generated wrong Fixnum from LONG_MIN. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * intern.h (rb_divmod): assume compilers `/` and `%` comply C99naruse2016-03-081-39/+7
| | | | | | | | | | | | | | | | | | | | | | and reduce branching. If a compiler doesn't comply, add #ifdefs. * intern.h (rb_div): added for Ruby's behavior. * intern.h (rb_mod): added for Ruby's behavior. * insns.def (opt_div): use rb_div. * insns.def (opt_mod): use rb_mod. * numeric.c (fixdivmod): removed. * numeric.c (fix_divide): use rb_div. * numeric.c (fix_mod): use rb_mod. * numeric.c (fix_divmod): use rb_divmod. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: wrong type step should raise TypeErrornobu2016-02-261-1/+29
| | | | | | | | * numeric.c (num_step_scan_args): comparison String with Numeric should raise TypeError. it is an invalid type, but not a mismatch the number of arguments. [ruby-core:62430] [Bug #9810] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: micro optimizationsnobu2016-02-241-5/+7
| | | | | | | * numeric.c (flo_to_s, rb_fix2str): use rb_usascii_str_new instead of rb_usascii_str_new_cstr, when the length can be calculated. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e