aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
Commit message (Collapse)AuthorAgeFilesLines
* get rid of a test failure with VC10.usa2016-12-121-16/+0
| | | | | | | | * 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
* numeric.c: fix exception message for nil roundingmrkn2016-12-061-1/+4
| | | | | | | | | * 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
* remove unnecessary variablenobu2016-12-061-1/+1
| | | | | | | | * 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
* round-downnobu2016-11-251-0/+39
| | | | | | | * 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
* complex.c: optimize f_gt_p some casesmrkn2016-11-221-6/+6
| | | | | | | | | | | | | | * 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
* numeric.c: refine error messagenobu2016-11-211-8/+14
| | | | | | | * 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
* complex.c: optimize f_negatemrkn2016-11-181-3/+3
| | | | | | | | | | | | | | | | * 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
* internal.h: round macrosnobu2016-11-181-11/+17
| | | | | | | * 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
* numeric.c: get rid of a compile error on mingw64usa2016-11-171-1/+1
| | | | | | | * numeric.c (rb_fix2str): typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c: optimize Numeric#polar and Numeric#argmrkn2016-11-161-4/+4
| | | | | | | | | | | | | | | | | | | * 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
* numeric.c: limit return valuenobu2016-11-131-1/+4
| | | | | | | * 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
* rational.c: optimize Integer#lcmmrkn2016-11-121-4/+4
| | | | | | | | | | | * 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
* rational.c: optimize Float#to_rmrkn2016-11-121-1/+1
| | | | | | | | | | * 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
* rational.c: optimize Rational#{floor,ceil,round,truncate}mrkn2016-11-121-7/+7
| | | | | | | | | | | | | | * 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
* rational.c: purge f_cmpmrkn2016-11-121-2/+0
| | | | | | | | | | | | | * 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
* rational.c: optimize Rational#==mrkn2016-11-121-4/+4
| | | | | | | | | | | | * 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
* rational.c: optimize Rational#<=>mrkn2016-11-121-5/+4
| | | | | | | | | | | | * 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
* rational.c: optimize Rational#**mrkn2016-11-111-4/+4
| | | | | | | | | | | | * 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
* rational.c: avoid needless object allocation with nurat_to_doublemrkn2016-11-111-22/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* numeric.c, rational.c: refactor by using FIXNUM_NEGATIVE_P and FIXNUM_ZERO_Pmrkn2016-11-111-6/+4
| | | | | | | | | | | * 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
* numeric.c, internal.h: export int_fdiv() as rb_int_fdiv()mrkn2016-11-101-3/+3
| | | | | | | | * 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
* Introduce table improvement by Vladimir Makarov <vmakarov@redhat.com>.ko12016-11-071-6/+1
| | | | | | | | | | | | | | | | | | | | | | | [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
* numeric.c: raise TypeError at wrong argumentnobu2016-11-051-2/+2
| | | | | | | * 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
* * numeric.c (rb_int_round): cast to SIGNED_VALUE to suppressshugo2016-11-051-1/+1
| | | | | | warnings by -Wsign-compare. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: round to nearest evennobu2016-11-051-14/+107
| | | | | | | | | * 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
* numeric.c (rb_int_digits): Fix exception messagemrkn2016-11-041-1/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: bit op with non-integernobu2016-11-011-20/+35
| | | | | | | * 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
* numeric.c: use rb_num_coerce_bitnobu2016-11-011-6/+3
| | | | | | | * 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
* numeric.c: fix return value on big 0nobu2016-11-011-1/+4
| | | | | | | * 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
* numeric.c: adjust indent [ci skip]nobu2016-11-011-12/+11
| | | | | | * numeric.c (rb_num2ulong_internal): adjust indent. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* numeric.c: fix typos [ci skip]nobu2016-11-011-2/+2
| | | | | | | * 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
* [DOC] replace Fixnum with Integer [ci skip]nobu2016-10-261-36/+12
| | | | | | * 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
* numeric.c: fix up r55891nobu2016-10-221-4/+4
| | | | | | | * 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
* * 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
* numeric.c: adjust typenobu2016-10-021-1/+1
| | | | | | | * 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
* * numeric.c (rb_fix2str): detect unnormalized Fixnum value.usa2016-10-011-0/+11
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fid typos [ci skip]nobu2016-09-241-1/+1
| | | | | | * 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
* 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
* numeric.c: round_to_nearestnobu2016-08-151-7/+26
| | | | | | | * 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
* numeric.c: infinite recursionnobu2016-08-131-21/+77
| | | | | | | * 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
* numeric.c, complex.c: Add finite? and infinite? consistent with Floatmrkn2016-07-171-0/+30
| | | | | | | | | | | | | | | | | | | | | | * 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
* complex.c: rb_complex prefixnobu2016-07-121-2/+2
| | | | | | | * 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
* numeric.c: round as doublenobu2016-07-081-2/+2
| | | | | | | * 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
* numeric.c: round nearly middle valuenobu2016-07-071-2/+9
| | | | | | | | | * 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
* numeric.c: fix doc of Integer#digits [ci skip]nobu2016-06-141-2/+2
| | | | | | | * 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
* numeric.c: Add Integer#digits [Feature #12447] [ruby-core:75799]mrkn2016-06-131-0/+107
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55395 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
* missing.h: isfinitenobu2016-05-231-8/+0
| | | | | | * 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
* ruby.h: RB_INTEGER_TYPE_Pnobu2016-05-181-3/+2
| | | | | | | | * 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
* Optimize enum_sum for a range from int to intmrkn2016-05-171-3/+3
| | | | | | | | | | | | | * 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