aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
Commit message (Collapse)AuthorAgeFilesLines
* rename rb_rational_add -> rb_rational_plusmrkn2016-04-151-2/+2
| | | | | | | | | | | * rational.c (rb_rational_plus): rename from rb_rational_add to be aligned with rb_fix_plus. * array.c (rb_ary_sum): ditto. * internal.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_sum): use rb_rational_add directlymrkn2016-04-151-3/+3
| | | | | | | | | | | * rational.c (rb_rational_add): rename from nurat_add. * array.c (rb_ary_sum): use rb_rational_add directly. * test/ruby/test_array.rb (test_sum): add assertions for an array of Rational values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: pure declarationsnobu2016-03-301-5/+2
| | | | | | | * rational.c (get_dat1, get_dat2): turn into pure variable declarations only, not mixed code and declarations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* RUBY_ASSERTnobu2016-01-221-1/+1
| | | | | | | * error.c (rb_assert_failure): assertion with stack dump. * ruby_assert.h (RUBY_ASSERT): new header for the assertion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: preserve encoding in exceptionnormal2015-09-111-3/+2
| | | | | | * rational.c (string_to_r_strict): preserve encoding in exception git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * remove trailing spaces.svn2015-04-301-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c: Added documentation for rational literal.hsbt2015-04-301-2/+3
| | | | | | [Bug #11075][fix GH-885][ci skip] Patch by @shishir127 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c: removed commented-out code.hsbt2015-01-101-4/+0
| | | | | | [Feature #10376][ruby-core:65643] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.h: Include ruby.h and ruby/encoding.h to beakr2014-11-151-1/+0
| | | | | | | | includable without prior inclusion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* provide backward compatibilitiesnobu2014-08-221-0/+2
| | | | | | | | | * complex.c (Init_Complex): provide the feature for backward compatibility. * rational.c (Init_Rational): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * include/ruby/ruby.h: Hide Rational internal.akr2014-05-171-0/+15
| | | | | | | | | | | | | | | | | | | | | | | (RRational): Moved to internal.h (RRATIONAL): Ditto. (RRATIONAL_SET_NUM): Moved to rational.c. (RRATIONAL_SET_DEN): Ditto. * rational.c (rb_rational_num): New function. (rb_rational_den): Ditto. * include/ruby/intern.h (rb_rational_num): Declared. (rb_rational_den): Ditto. * ext/bigdecimal/bigdecimal.c: Follow the above change. * ext/date/date_core.c: Ditto. [ruby-core:60665] [Feature #9513] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* avoid large alloca on Complex/Rational callsnormal2014-05-021-1/+3
| | | | | | | | * complex.c (parse_comp): replace ALLOCA_N with ALLOCV_N/ALLOCV_END [Bug #9608] * rational.c (read_digits): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.h (struct RBignum): Use size_t for len.akr2014-04-191-2/+2
| | | | | | | | | | | | | | | | * include/ruby/intern.h (rb_big_new): Use size_t instead of long to specify the size of bignum. (rb_big_resize): Ditto. * bignum.c: Follow above changes. * rational.c: Follow above changes. * marshal.c: Follow above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * bignum.c (SIZEOF_BDIGIT): Renamed from SIZEOF_BDIGITS.akr2014-04-131-2/+2
| | | | | | | | | | | | * internal.h: Ditto. * marshal.c: Ditto. * rational.c: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complax.c: [DOC] Document number conversion of `nil` by @skade [fix ↵hsbt2014-03-211-0/+2
| | | | | | | | GH-570] [ci skip] * object.c, rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* unused functions and variablesnobu2014-03-171-35/+1
| | | | | | | | | | | | * complex.c, rational.c: remove unused functions, which are warned by clang 5.1, and also variables only used by removed functions. * ext/date/date_core.c: ditto. * enc/utf_16be.c, enc/utf_16le.c: comment out constants only used by commented out functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.h: Rename macro names: RBIGNUM_FOO to BIGNUM_FOO.akr2014-02-151-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (BIGNUM_EMBED_LEN_NUMBITS): Renamed from RBIGNUM_EMBED_LEN_NUMBITS. (BIGNUM_EMBED_LEN_MAX): Renamed from RBIGNUM_EMBED_LEN_MAX. (BIGNUM_SIGN_BIT): Renamed from RBIGNUM_SIGN_BIT. (BIGNUM_SIGN): Renamed from RBIGNUM_SIGN. (BIGNUM_SET_SIGN): Renamed from RBIGNUM_SET_SIGN. (BIGNUM_POSITIVE_P): Renamed from RBIGNUM_POSITIVE_P. (BIGNUM_NEGATIVE_P): Renamed from RBIGNUM_NEGATIVE_P. (BIGNUM_EMBED_FLAG): Renamed from RBIGNUM_EMBED_FLAG. (BIGNUM_EMBED_LEN_MASK): Renamed from RBIGNUM_EMBED_LEN_MASK. (BIGNUM_EMBED_LEN_SHIFT): Renamed from RBIGNUM_EMBED_LEN_SHIFT. (BIGNUM_LEN): Renamed from RBIGNUM_LEN. (RBIGNUM_DIGITS): Renamed from RBIGNUM_DIGITS. (BIGNUM_LENINT): Renamed from RBIGNUM_LENINT. * bignum.c: Follow the above change. * gc.c: Ditto. * marshal.c: Ditto. * math.c: Ditto. * numeric.c: Ditto. * random.c: Ditto. * rational.c: Ditto. * sprintf.c: Ditto. * ext/-test-/bignum/bigzero.c: Ditto. * ext/-test-/bignum/intpack.c: Ditto. * ext/bigdecimal/bigdecimal.c: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revertd.tadf2013-09-171-12/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert r42942; a revert requires a reasonnaruse2013-09-171-1/+12
| | | | | | * rational.c (nurat_div): reverted r28844, r28886 and r28887. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c: removed meaningless lines.tadf2013-09-151-2/+0
| | | | | | | * rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* removed an empty line.tadf2013-09-151-1/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c (nurat_div): reverted r28844, r28886 and r28887.tadf2013-09-151-12/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: conditionally defined variablenobu2013-09-101-1/+6
| | | | | | | * rational.c (numeric_quo): variable 'canonicalization' is defined conditionally by CANON (and CANONICALIZATION_FOR_MATHN). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* complex.c, rational.c: use RB_TYPE_Pnobu2013-09-091-105/+93
| | | | | | | * complex.c, rational.c: use RB_TYPE_P() for special classes instead of switch with TYPE(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c (f_gcd): Relax the condition to use GMP.akr2013-09-081-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c: Include gmp.h if GMP is used.akr2013-09-061-1/+54
| | | | | | | | | | | | | | | | | | (GMP_GCD_DIGITS): New macro. (rb_gcd_gmp): New function. (f_gcd_normal): Renamed from f_gcd. (rb_gcd_normal): New function. (f_gcd): Invoke rb_gcd_gmp or f_gcd_normal. * internal.h (rb_gcd_normal): Declared. (rb_gcd_gmp): Ditto. * ext/-test-/rational: New directory. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c (rb_flt_rationalize_with_prec): new public C functionmrkn2013-08-011-38/+58
| | | | | | | | | | | | | | | | | | | to rationalize a Float instance with a precision. * rational.c (rb_flt_rationalize): new public C function to rationalize a Float instance. A precision is calculated from the given float number. * include/ruby/intern.h: Add rb_flt_rationalize_with_prec and rb_flt_rationalize. * parse.y: implement number literal suffixes, 'r' and 'i'. [ruby-core:55096] [Feature #8430] * bootstraptest/test_literal_suffix.rb: add tests for parser to scan number literals with the above tsuffixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* rational.c: ensure to be Rationalnobu2013-07-261-0/+4
| | | | | | | | * rational.c (f_round_common): Rational is expected to be returned by Rational#*, but mathn.rb breaks that assumption. [ruby-core:56177] [Bug #8687] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c (numeric_quo): move num_quo in numeric.c to numeric_quomrkn2013-06-071-0/+27
| | | | | | | | | | | 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
* rational.c: use existing functionsnobu2013-05-291-6/+4
| | | | | | | * rational.c (f_inspect, f_to_s): use existing functions, rb_inspect and rb_obj_as_string respectively. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * gc.c: support RGENGC. [ruby-trunk - Feature #8339]ko12013-05-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* * include/ruby/ruby.h: constify RRational::(num,den) andko12013-05-131-4/+4
| | | | | | | | | | | | | | | | | RComplex::(real,imag). Add macro to set these values: * RRATIONAL_SET_NUM() * RRATIONAL_SET_DEN() * RCOMPLEX_SET_REAL() * RCOMPLEX_SET_IMAG() This change is a part of RGENGC branch [ruby-trunk - Feature #8339]. TODO: API design. RRATIONAL_SET(rat,num,den) is enough? TODO: Setting constify variable with cast has same issue of r40691. * complex.c, rational.c: use above macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * *.c, parse.y, insns.def: use RARRAY_AREF/ASET macroko12013-05-131-3/+3
| | | | | | | | instead of using RARRAY_PTR(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.h (MUL_OVERFLOW_SIGNED_INTEGER_P): New macro.akr2013-04-091-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | (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
* * rational.c: fix dangling if, else-if and else.takano322013-03-121-6/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c: edited rdoc.tadf2013-03-101-1/+7
| | | | | | | * rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c: described syntax of string form.tadf2013-03-101-0/+12
| | | | | | | * rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c: Document #<=> return values and formattingzzak2013-02-231-1/+3
| | | | | | | | | | | | | * 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
* * rational.c (nurat_expt): Deal with special cases for rationals 0, ±1marcandre2013-02-051-0/+46
| | | | | | [bug #5713] [bug #5715] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* marshal.c: marshal_dump instance varialbesnobu2013-01-261-0/+1
| | | | | | | | | * marshal.c (w_object): dump instance varialbes of the result of marshal_dump not the original object. [ruby-core:51163] [Bug #7627] * complex.c (nucomp_marshal_dump): need to copy instance variables. * rational.c (nurat_marshal_dump): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c (f_round_common): should check overflow.tadf2012-12-151-0/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ratioanl.c (float_rationalize): reduced.tadf2012-12-151-10/+18
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c, rational.c: make marshal methods privatenobu2012-12-031-2/+2
| | | | | | | | * random.c (Init_Random), rational.c (Init_Rational): make marshal methods private. [Feature #6539] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c (string_to_c_strict, string_to_c): check NUL.tadf2012-11-221-3/+21
| | | | | | | * rational.c (string_to_r_strict, string_to_r): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * rational.c (read_digits): due to a bit tighter rb_cstr_to_inum().tadf2012-11-211-2/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c: some improvements.tadf2012-11-201-14/+35
| | | | | | | * rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c (read_comp): mathn compliant.tadf2012-11-181-2/+2
| | | | | | | * rational.c (read_num): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* trivial changes.tadf2012-11-181-7/+10
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c (string_to_c_strict, string_to_c): rewrote without regexp.tadf2012-11-171-125/+167
| | | | | | | * rational.c (string_to_r_strict, string_to_r): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c: modified doc.tadf2012-11-101-5/+10
| | | | | | | * ratioanl.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e