* 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
* 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
* 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
* 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
* 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
* 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
* 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
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
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
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
* 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
* 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
* 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
* 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
* 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
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
* 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
* 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
* 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
* 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
* 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
* 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 (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
* 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
* 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
* 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 (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