Граф коммитов

447 Коммитов

Автор SHA1 Сообщение Дата
nobu 09b02349c2 numeric.c: no declaration of finite
* numeric.c (finite): disable declaration on Windows, which can be
  defined in ruby/win32.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 06:33:34 +00:00
mame 487a25d29b * numeric.c (fix_aref): avoid a possible undefined behavior.
1L << 63 on 64-bit platform is undefined, at least, according to
  ISO/IEC 9899 (C99) 6.5.7.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-09 15:08:41 +00:00
nobu d700d34043 internal.h: move inline functions
* internal.h (rb_float_value, rb_float_new): move inline functions
  from ruby/ruby.h.
* numeric.c (rb_float_value, rb_float_new): define external functions
  for extension libraries.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-25 07:58:49 +00:00
nobu ed6c17f75c numeric.c: use RB_TYPE_P
* numeric.c: use RB_TYPE_P() for special classes instead of switch
  with TYPE().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-11 08:23:06 +00:00
nobu 9b6ee42d86 numeric.c: use positive_int_p
* numeric.c (NUM_STEP_SCAN_ARGS): use positive_int_p() to fix rubyspec
  failures.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-07 19:04:33 +00:00
nobu ba6c734847 numeric.c: no extra checks
* numeric.c (NUM_STEP_SCAN_ARGS): remove extra class checks, which
  cause the incompatibilities.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-07 19:04:28 +00:00
nobu 326e38164b numeric.c: split NUM_STEP_GET_INF
* numeric.c (NUM_STEP_GET_INF): split from NUM_STEP_SCAN_ARGS(), since
  inf is not used in num_step_size().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 13:57:02 +00:00
knu c68596aef1 Retain behavior of Numeric#step when nil is given as second argument.
* numeric.c (NUM_STEP_SCAN_ARGS): On sencond thought, keep
  Numeral#step backward compatible in that it raises TypeError
  when nil is given as second argument.

* test/ruby/test_float.rb (TestFloat#test_num2dbl): Revert.

* test/ruby/test_numeric.rb (TestNumeric#test_step): Fix test
  cases for the above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-02 22:54:58 +00:00
knu 4993cf9e24 Numeral#step should raise TypeError if a non-numeric parameter is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-02 22:39:22 +00:00
knu fd4b5b8dc8 Enhance Numeric#step.
* numeric.c (num_step): Default the limit argument to infinity and
  allow it to be omitted.  Keyword arguments (by: and to:) are
  introduced for ease of use. [Feature #8838] [ruby-dev:47662]
  [ruby-dev:42194]

* numeric.c (num_step): Optimize for infinite loop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-02 14:56:06 +00:00
akr 77f245e62e * numeric.c (rb_fix_bit_length): Moved from bignum.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 01:31:16 +00:00
ktsj 22bfbc9419 * numeric.c: [DOC] fix typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42491 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-10 05:02:56 +00:00
akr ba3ec382c7 [DOC] refine a call seq.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-06 03:33:22 +00:00
nobu 7c9a3d19fc parse.y: calculate powers of ten
* parse.y (parser_yylex): calculate denominator directly as powers of
  ten, not parsing string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 14:48:55 +00:00
zzak 4314d8c2e3 * numeric.c: [DOC] improve rdoc formatting for parameters and links
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 18:27:23 +00:00
zzak ceda881601 * numeric.c (rb_cNumeric): [DOC] Added comment for Numeric to fix doc
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 02:33:58 +00:00
nobu 9487b2cdfc numeric.c: for strict ANSI
* numeric.c (finite): add declaration for strict ANSI.
  [ruby-core:55312] [Bug #8495]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 14:12:52 +00:00
charliesome 7ffd3e9444 * numeric.c (fix_mul): remove FIT_SQRT_LONG test as it was causing
fix_mul to return an incorrect result for -2147483648*-2147483648
  on 64 bit platforms

* test/ruby/test_integer_comb.rb (class TestIntegerComb): add test case

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-28 16:09:08 +00:00
nobu 5e2f227d21 intern.h: define rb_enumerator_size_func
* include/ruby/intern.h (rb_enumerator_size_func): define strict
  function declaration for rb_enumeratorize_with_size().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-26 13:43:22 +00:00
akr 633e4949bd * numeric.c (rb_num_to_uint): Use rb_absint_size instead of
RBIGNUM_LEN.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 14:57:28 +00:00
mrkn 5385ae9af4 * rational.c (numeric_quo): move num_quo in numeric.c to numeric_quo
in rational.c to refer canonicalization state for mathn support.
  [ruby-core:41575] [Bug #5736]

* numeric.c (num_quo): ditto.

* test/test_mathn.rb: add a test for the change at r41109.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-07 02:50:32 +00:00
eregon 896619c77b * numeric.c: remove unused ID id_to_r introduced in r41109.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-06 21:49:45 +00:00
mrkn 7708560bb1 * numeric.c (num_quo): Use to_r method to convert the receiver to
rational.  [ruby-core:41575] [Bug #5736]

* test/ruby/test_numeric.rb: add a test for the above change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-06 13:31:22 +00:00
mrkn febc42d05c * numeric.c (num_quo): should return a Float for a Float argument.
[ruby-dev:44710] [Bug #5515]

* test/ruby/test_fixnum.rb: Add an assertion for the above change.

* test/ruby/test_bignum.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-06 01:04:11 +00:00
ko1 4f401816ff * gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
  check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
  you want to access raw pointers. If you modify the contents which
  pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
  and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
  barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
  generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
  FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
  move flag bits.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 18:07:47 +00:00
ko1 aacd771046 * *.c, parse.y, insns.def: use RARRAY_AREF/ASET macro
instead of using RARRAY_PTR().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 09:56:22 +00:00
zzak 704abdc3d2 * numeric.c: Fix wiki link on Float imprecision in overview, patched
by Makoto Kishimoto [Bug #8304] [ruby-dev:47280]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-24 05:08:47 +00:00
zzak 9ef4e13459 * array.c: Document synonymous methods, by windwiny [GH-277]
* bignum.c: ditto
* complex.c: ditto
* dir.c: ditto
* encoding.c: ditto
* enumerator.c: ditto
* numeric.c: ditto
* proc.c: ditto
* re.c: ditto
* string.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-12 02:59:07 +00:00
akr 712c7168bf * internal.h (MUL_OVERFLOW_SIGNED_INTEGER_P): New macro.
(MUL_OVERFLOW_FIXNUM_P): Ditto.
  (MUL_OVERFLOW_LONG_P): Ditto.

* array.c (rb_ary_product): Don't overflow on signed integer
  multiplication.

* numeric.c (fix_mul): Ditto.
  (int_pow): Ditto.

* rational.c (f_imul): Ditto.

* insns.def (opt_mult): Ditto.

* thread.c (sleep_timeval): Don't overflow on signed integer addition.

* bignum.c (rb_int2big): Don't overflow on signed integer negation.
  (rb_big2ulong): Ditto.
  (rb_big2long): Ditto.
  (rb_big2ull): Ditto.
  (rb_big2ll): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-09 11:39:53 +00:00
akr d6daffbbf0 * numeric.c (rb_num2ulong_internal): Don't cast a negative double value
into unsigned long, which is undefined behavior.
  (rb_num2ull): Don't cast a value bigger than LLONG_MAX into
  long long, which is undefined behavior.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-01 12:14:30 +00:00
akr 4e52c3c60c * numeric.c (rb_num2long): Don't use SIGNED_VALUE uselessly.
(check_int): Ditto.
  (check_short): Ditto.
  (rb_num2fix): Ditto.
  (rb_num2ulong_internal): Add a cast.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-01 11:08:44 +00:00
akr 92f59c6d79 * numeric.c (check_uint): Take the 1st argument as unsigned long,
instead of VALUE.  Refine the validity test conditions.
  (check_ushort): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-01 03:06:09 +00:00
akr 59182ccf69 * numeric.c (rb_num2ulong_internal): New function similart to
rb_num2ulong but integer wrap around flag is also returned.
  (rb_num2ulong): Use rb_num2ulong_internal.
  (rb_num2uint): Use rb_num2ulong_internal and the wrap around flag is
  used instead of negative_int_p(val).
  (rb_num2ushort): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-31 04:51:29 +00:00
akr 1950c1ce6c * numeric.c (rb_num2ull): Cast double to unsigned LONG_LONG via
LONG_LONG instead of double to unsigned LONG_LONG directly.
  This is a challenge to fix a test_num2ull(TestNum2int)
  failure (NUM2ULL(-1.0) should be "18446744073709551615" but was "0")
  on Mac OS X with 32bit clang.
  http://a.mrkn.jp/~mrkn/chkbuild/mountain_lion/ruby-trunk-m32-o0/log/20130328T191100Z.diff.html.gz


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-28 21:49:55 +00:00
akr 83f1be1bc3 * numeric.c (LONG_MIN_MINUS_ONE_IS_LESS_THAN): New macro.
(LLONG_MIN_MINUS_ONE_IS_LESS_THAN): Ditto.
  (rb_num2long): Use LONG_MIN_MINUS_ONE_IS_LESS_THAN.
  (rb_num2ulong): Ditto.
  (rb_num2ll): Use LLONG_MIN_MINUS_ONE_IS_LESS_THAN.
  (rb_num2ull): Ditto.

* test/-ext-/num2int/test_num2int.rb (asert_num2i_success): Test the
  value converted into a Float if Float can represent the value
  exactly.
  (asert_num2i_error): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-27 13:12:27 +00:00
nobu 2d1c94a18d prefix global symbols
* iseq.c (rb_insn_operand_intern): prefix global symbols.

* numeric.c (ruby_num_interval_step_size): ditto.

* vm_backtrace.c (rb_vm_backtrace_str_ary),
  (rb_vm_backtrace_location_ary, rb_vm_thread_backtrace),
  (rb_vm_thread_backtrace_locations): ditto.

* vm_trace.c (rb_vm_trace_mark_event_hooks): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-06 06:30:03 +00:00
nobu 4a429c11e1 enumerator.c: allow Bignum for with_index
* enumerator.c (enumerator_with_index_i): allow Bignum as offset, to
  get rid of conversion exception and integer overflow.
  [ruby-dev:47131] [Bug #8010]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-05 01:20:20 +00:00
nobu ce357ef152 numeric.c: optimize for Bignum
* numeric.c (rb_int_succ, rb_int_pred): shortcut optimization for
  Bignum.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-05 01:18:55 +00:00
zzak c2204ca328 * array.c: Document #<=> return values and formatting
* bignum.c: ditto
* file.c: ditto
* object.c: ditto
* numeric.c: ditto
* rational.c: ditto
* string.c: ditto
* time.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 03:35:38 +00:00
nobu 3f2ce6373f random.c: fix error message
* random.c (rb_random_ulong_limited): fix error message for negative
  value.  [ruby-dev:47061] [Bug #7903]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-22 03:46:47 +00:00
zzak 8d4a11c919 * numeric.c: Examples and formatting for Numeric and Float
Based on a patch by Zach Morek and Oren K of newhaven.rb
  [Github documenting-ruby/ruby#5]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-22 02:01:28 +00:00
marcandre d22ce4a522 * numeric.c (fix_pow): Handle special cases when base is 0, -1 or +1
[Bug #5713] [Bug #5715]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-05 05:39:49 +00:00
marcandre 075ae2955c * numeric.c: Fix rdoc for Fixnum#**
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-05 05:39:16 +00:00
zzak a954def1fb * numeric.c: Document Float constants [ruby-core:51484] [Bug #7709]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-03 00:59:51 +00:00
mrkn 350c448da8 * numeric.c (do_coerce): fix for the exceptions which the coerce
method raises.  The optimization done by r38756 is preserved.
  [Bug #7645] [ruby-core:51213]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-12 08:47:18 +00:00
eregon 8307cb90a0 * numeric.c (do_coerce): fix comment and adjust indent
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-10 08:12:58 +00:00
shugo 42eadff3a1 * numeric.c (do_coerce): remove an unused variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-10 06:57:17 +00:00
mrkn 9aa75d08ce * numeric.c (do_coerce): speed optimization by using rb_check_funcall
instead of rb_rescue + rb_funcall.
  This fix is based on the patch by Benoit Daloze.
  [Bug #7645] [ruby-core:51213]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-10 06:30:23 +00:00
nobu e878df745c use RB_TYPE_P
* enumerator.c (enumerator_initialize), eval.c (rb_using_refinement),
  (add_activated_refinement), numeric.c (num_interval_step_size),
  parse.y (arg, match_op_gen, cond0), range.c (range_bsearch),
  vm_insnhelper.c (vm_get_iclass): use RB_TYPE_P() to optimize.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-29 12:22:01 +00:00
mrkn a756488c6d * include/ruby/intern.h: add the prototype declaration of
rb_num_coerce_bit.

* numeric.c (rb_num_coerce_bit): the new coerce function for bitwise
  binary operation.

* bignum.c (rb_big_and): use coerce to convert the argument, which isn't
  a Fixnum nor a Bignum, to the corresponding Integer object so that
  bitwise operations can support Integer-mimic objects.
  [Bug #1792] [ruby-core:39491]

* bignum.c (rb_big_or): ditto.

* bignum.c (rb_big_xor): ditto.

* numeric.c (bit_coerce): ditto.

* numeric.c (fix_and): ditto.

* numeric.c (fix_or): ditto.

* numeric.c (fix_xor): ditto.

* test/ruby/test_integer.rb: add tests for the above changes.

* test/ruby/test_bignum.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 15:06:22 +00:00