summaryrefslogtreecommitdiff
path: root/numeric.c
AgeCommit message (Collapse)Author
2017-05-27numeric.c: fix for small numbernobu
* numeric.c (flo_floor, flo_ceil): should not return zero for small number. [ruby-core:81394] [Bug #13599] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-26numeric.c: remove duplicate codenobu
* numeric.c (flo_to_i): use dbl2ival and reduce duplicate code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25vm_insnhelper.c: rb_eql_opt should call eql?nobu
* vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and String, not #==. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-06make Integer#{round,floor,ceil,truncate} always return integerstomar
* numeric.c (int_round): return integer (self) instead of float for Integer#round with positive ndigits argument, because conversion to float introduces errors for large integers. * numeric.c (int_floor): ditto for Integer#floor. * numeric.c (int_ceil): ditto for Integer#ceil. * numeric.c (int_truncate): ditto for Integer#truncate. * test/ruby/test_integer.rb: adjust test cases and add some more. [ruby-core:80645] [Bug #13420] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-06numeric.c: remove mention of Bignum from docsstomar
* numeric.c: [DOC] remove mention of Bignum from Integer#{+,-,*,/}, the return type does not depend on magnitude anymore. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-06numeric.c: revise docsstomar
* numeric.c: [DOC] revise docs for Numeric, Integer, Float: * nodoc Numeric#singleton_method_added * mention that result for Integer#** might also be Complex * add / simplify / fix some examples * mention aliases * fix rdoc formatting, typos, grammar * clarifications and other improvements git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25no longer rescue exceptions of #coerce in Integer#steperegon
* numeric.c (num_step_negative_p): no more error hiding. * test/ruby/test_float.rb, test/ruby/test_numeric.rb: follow the change. [Feature #7688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25no longer rescue exceptions in numeric comparison operationseregon
* numeric.c (do_coerce): no more error hiding. * test/ruby/test_numeric.rb: follow the change. [Feature #7688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-15ruby.h: check argc to rb_funcallnobu
* include/ruby/ruby.h (rb_funcall): check if argc matches the number of variadic arguments, and replace with rb_funcallv. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-13array.c: Improve performance of Array#sort with float elementsmrkn
* array.c (sort_2): improve performance of Array#sort with float elements. * internal.h (cmp_opt_Float, cmp_opt_data): added for checking whether or not Float#<=> can be optimizable. * numeric.c (rb_float_cmp): added for internal use. * internal.h (rb_float_cmp): ditto. [Bug #13340] [ruby-dev:50023] [Fix GH-1539] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-09numeric.c: improve docs for Floatstomar
* numeric.c: [DOC] mention possibly surprising behavior of Float#{floor,ceil,to_i,truncate} due to floating point arithmetic. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03improve docs for #truncate, #floor, and #ceil methodsstomar
* numeric.c: [DOC] improve and harmonize documentation for {Float,Integer,Numeric}#{truncate,floor,ceil}. * rational.c: [DOC] ditto for Rational#{truncate,floor,ceil}. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03improve docs for #round methodsstomar
* numeric.c: [DOC] improve and harmonize documentation for {Float,Integer,Numeric}#round. * rational.c: [DOC] ditto for Rational#round. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-28numeric.c: improves Integer#round rdoc [ci skip]nobu
* numeric.c (int_round): [DOC] improves Integer#round documentation as well as Float#round. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-28numeric.c: improves Float#round rdoc [ci skip]nobu
* numeric.c (flo_round): [DOC] improves Float#round documentation to better highlight the half keyword. [Fix GH-1541] Author: Evan Brodie <brodie.evan@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58190 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-08re-introduce __builtin_add_overflowshyouhei
r57789 (74cdd89) was gradually "improve"d by naruse through r57793 to r57806, resulted in reverting the efect of r57789 while retaining its complexity. I think the current situation is slightly worse than before (same output complicated source code). Here I introduce __builtin_add_overflow again, which (I think) is what naruse wanted to do in r57793. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57807 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-03-06opt_eq_func refactornobu
* vm_insnhelper.c (opt_eq_func): method to dispatch is resolved by only the receiver's class, not including the argument class. even if basic operation is redefined, other class conditions never meet. optimize Float and non-Float case, delegate to rb_float_equal directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-02[DOC] update doc.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57761 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-28numeric.c: suppress warningnobu
* numeric.c (DEFINE_INT_SQRT): suppress a type-limits warning where int is always smaller than double. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-26Add rdoc for Integer.sqrtstomar
* numeric.c (rb_int_s_isqrt): [DOC] add rdoc for Integer.sqrt. [ruby-core:79762] [Bug #13251] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-24Integer.sqrt argument checknobu
* numeric.c (rb_int_s_isqrt): check if the argument is an integer. [Feature #13219] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57706 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-22rational.c: infinity in powernobu
* rational.c (nurat_expt): return Infinity due to overflow. [ruby-core:79686] [Bug #13242]: git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22numeric.c: Numeric#clone and #dupnobu
* numeric.c (num_clone, num_dup): no longer raises TypeError, returns the receiver instead as well as Integer and Float. [ruby-core:79636] [Bug #13237] * object.c (rb_immutable_obj_clone): immutable object clone with freeze optional keyword argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-02Use carry flag to reduce instructionsnaruse
NOTE: (1) Fixnum's LSB is always 1. It means you can always run `x - 1` without overflow. (2) Of course `z = x + (y-1)` may overflow. Now z's LSB is always 1, and the MSB of true result is also 1. You can get true result in long as `(1<<63)|(z>>1)`, and it equals to `(z<<63)|(z>>1)` == `ror(z)`. GCC and Clang have __builtin_add_ovewflow: * https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html * https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-10numeric.c: short circuit optimizationnobu
* numeric.c (fix_mul): short circuit when multiplication of Bignum and 0 or 1 not to make a Bignum unnecessarily. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-05numeric.c: short circuitnobu
* numeric.c (int_pow): short circuit when y is 0, always return 1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-28numeric.c: reduce fdivnobu
* numeric.c (rb_int_fdiv_double): reduce first for more precise result. [ruby-core:78886] [Bug #13078] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21numeric.c: remove not used linesyui-knk
* numeric.c (rb_num_get_rounding_option): remove not used lines. After r57130 these lines are never reached. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21[DOC] itemize values for half option of Float#round.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21numeric.c: rdoc of half option [ci skip]nobu
* numeric.c (flo_round): [DOC] mention half option. [Bug #12548] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-21numeric.c: allow nil as rounding mode optionnobu
* numeric.c (rb_num_get_rounding_option): allow nil same as the default behavior, per [ruby-core:77961]. [Bug #12548] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-12get rid of a test failure with VC10.usa
* 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
2016-12-06numeric.c: fix exception message for nil roundingmrkn
* 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
2016-12-06remove unnecessary variablenobu
* 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
2016-11-25round-downnobu
* 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
2016-11-22complex.c: optimize f_gt_p some casesmrkn
* 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
2016-11-21numeric.c: refine error messagenobu
* 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
2016-11-18complex.c: optimize f_negatemrkn
* 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
2016-11-18internal.h: round macrosnobu
* 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
2016-11-17numeric.c: get rid of a compile error on mingw64usa
* numeric.c (rb_fix2str): typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-16complex.c: optimize Numeric#polar and Numeric#argmrkn
* 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
2016-11-13numeric.c: limit return valuenobu
* 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
2016-11-12rational.c: optimize Integer#lcmmrkn
* 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
2016-11-12rational.c: optimize Float#to_rmrkn
* 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
2016-11-12rational.c: optimize Rational#{floor,ceil,round,truncate}mrkn
* 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
2016-11-12rational.c: purge f_cmpmrkn
* 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