summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c329
1 files changed, 231 insertions, 98 deletions
diff --git a/complex.c b/complex.c
index 943d9e4121..85d724f273 100644
--- a/complex.c
+++ b/complex.c
@@ -397,7 +397,7 @@ nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag)
RCOMPLEX_SET_REAL(obj, real);
RCOMPLEX_SET_IMAG(obj, imag);
- OBJ_FREEZE_RAW((VALUE)obj);
+ OBJ_FREEZE((VALUE)obj);
return (VALUE)obj;
}
@@ -411,15 +411,15 @@ nucomp_s_alloc(VALUE klass)
inline static VALUE
f_complex_new_bang1(VALUE klass, VALUE x)
{
- assert(!RB_TYPE_P(x, T_COMPLEX));
+ RUBY_ASSERT(!RB_TYPE_P(x, T_COMPLEX));
return nucomp_s_new_internal(klass, x, ZERO);
}
inline static VALUE
f_complex_new_bang2(VALUE klass, VALUE x, VALUE y)
{
- assert(!RB_TYPE_P(x, T_COMPLEX));
- assert(!RB_TYPE_P(y, T_COMPLEX));
+ RUBY_ASSERT(!RB_TYPE_P(x, T_COMPLEX));
+ RUBY_ASSERT(!RB_TYPE_P(y, T_COMPLEX));
return nucomp_s_new_internal(klass, x, y);
}
@@ -432,7 +432,7 @@ nucomp_real_check(VALUE num)
!RB_TYPE_P(num, T_RATIONAL)) {
if (RB_TYPE_P(num, T_COMPLEX) && nucomp_real_p(num)) {
VALUE real = RCOMPLEX(num)->real;
- assert(!RB_TYPE_P(real, T_COMPLEX));
+ RUBY_ASSERT(!RB_TYPE_P(real, T_COMPLEX));
return real;
}
if (!k_numeric_p(num) || !f_real_p(num))
@@ -799,9 +799,9 @@ rb_complex_imag(VALUE self)
/*
* call-seq:
- * -complex -> new_complex
+ * -self -> complex
*
- * Returns the negation of +self+, which is the negation of each of its parts:
+ * Returns +self+, negated, which is the negation of each of its parts:
*
* -Complex.rect(1, 2) # => (-1-2i)
* -Complex.rect(-1, -2) # => (1+2i)
@@ -816,17 +816,26 @@ rb_complex_uminus(VALUE self)
}
/*
- * call-seq:
- * complex + numeric -> new_complex
+ * call-seq:
+ * self + other -> numeric
+ *
+ * Returns the sum of +self+ and +other+:
+ *
+ * Complex(1, 2) + 0 # => (1+2i)
+ * Complex(1, 2) + 1 # => (2+2i)
+ * Complex(1, 2) + -1 # => (0+2i)
+ *
+ * Complex(1, 2) + 1.0 # => (2.0+2i)
+ *
+ * Complex(1, 2) + Complex(2, 1) # => (3+3i)
+ * Complex(1, 2) + Complex(2.0, 1.0) # => (3.0+3.0i)
*
- * Returns the sum of +self+ and +numeric+:
+ * Complex(1, 2) + Rational(1, 1) # => ((2/1)+2i)
+ * Complex(1, 2) + Rational(1, 2) # => ((3/2)+2i)
*
- * Complex.rect(2, 3) + Complex.rect(2, 3) # => (4+6i)
- * Complex.rect(900) + Complex.rect(1) # => (901+0i)
- * Complex.rect(-2, 9) + Complex.rect(-9, 2) # => (-11+11i)
- * Complex.rect(9, 8) + 4 # => (13+8i)
- * Complex.rect(20, 9) + 9.8 # => (29.8+9i)
+ * For a computation involving Floats, the result may be inexact (see Float#+):
*
+ * Complex(1, 2) + 3.14 # => (4.140000000000001+2i)
*/
VALUE
rb_complex_plus(VALUE self, VALUE other)
@@ -852,9 +861,9 @@ rb_complex_plus(VALUE self, VALUE other)
/*
* call-seq:
- * complex - numeric -> new_complex
+ * self - other -> complex
*
- * Returns the difference of +self+ and +numeric+:
+ * Returns the difference of +self+ and +other+:
*
* Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
* Complex.rect(900) - Complex.rect(1) # => (899+0i)
@@ -913,15 +922,16 @@ comp_mul(VALUE areal, VALUE aimag, VALUE breal, VALUE bimag, VALUE *real, VALUE
/*
* call-seq:
- * complex * numeric -> new_complex
+ * self * other -> numeric
*
- * Returns the product of +self+ and +numeric+:
+ * Returns the numeric product of +self+ and +other+:
*
+ * Complex.rect(9, 8) * 4 # => (36+32i)
+ * Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
* Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
* Complex.rect(900) * Complex.rect(1) # => (900+0i)
* Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
- * Complex.rect(9, 8) * 4 # => (36+32i)
- * Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
+ * Complex.rect(9, 8) * Rational(2, 3) # => ((6/1)+(16/3)*i)
*
*/
VALUE
@@ -989,9 +999,9 @@ f_divide(VALUE self, VALUE other,
/*
* call-seq:
- * complex / numeric -> new_complex
+ * self / other -> complex
*
- * Returns the quotient of +self+ and +numeric+:
+ * Returns the quotient of +self+ and +other+:
*
* Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
* Complex.rect(900) / Complex.rect(1) # => (900+0i)
@@ -1066,8 +1076,11 @@ complex_pow_for_special_angle(VALUE self, VALUE other)
x = dat->imag;
dir = 3;
}
+ else {
+ dir = 0;
+ }
- if (x == Qundef) return x;
+ if (UNDEF_P(x)) return x;
if (f_negative_p(x)) {
x = f_negate(x);
@@ -1109,9 +1122,9 @@ complex_pow_for_special_angle(VALUE self, VALUE other)
/*
* call-seq:
- * complex ** numeric -> new_complex
+ * self ** exponent -> complex
*
- * Returns +self+ raised to power +numeric+:
+ * Returns +self+ raised to the power +exponent+:
*
* Complex.rect(0, 1) ** 2 # => (-1+0i)
* Complex.rect(-8) ** Rational(1, 3) # => (1.0000000000000002+1.7320508075688772i)
@@ -1139,7 +1152,7 @@ rb_complex_pow(VALUE self, VALUE other)
}
VALUE result = complex_pow_for_special_angle(self, other);
- if (result != Qundef) return result;
+ if (!UNDEF_P(result)) return result;
if (RB_TYPE_P(other, T_COMPLEX)) {
VALUE r, theta, nr, ntheta;
@@ -1213,10 +1226,10 @@ rb_complex_pow(VALUE self, VALUE other)
/*
* call-seq:
- * complex == object -> true or false
+ * self == other -> true or false
*
- * Returns +true+ if <tt>self.real == object.real</tt>
- * and <tt>self.imag == object.imag</tt>:
+ * Returns whether both <tt>self.real == other.real</tt>
+ * and <tt>self.imag == other.imag</tt>:
*
* Complex.rect(2, 3) == Complex.rect(2.0, 3.0) # => true
*
@@ -1247,14 +1260,16 @@ nucomp_real_p(VALUE self)
/*
* call-seq:
- * complex <=> object -> -1, 0, 1, or nil
+ * self <=> other -> -1, 0, 1, or nil
+ *
+ * Compares +self+ and +other+.
*
* Returns:
*
- * - <tt>self.real <=> object.real</tt> if both of the following are true:
+ * - <tt>self.real <=> other.real</tt> if both of the following are true:
*
* - <tt>self.imag == 0</tt>.
- * - <tt>object.imag == 0</tt>. # Always true if object is numeric but not complex.
+ * - <tt>other.imag == 0</tt> (always true if +other+ is numeric but not complex).
*
* - +nil+ otherwise.
*
@@ -1267,6 +1282,8 @@ nucomp_real_p(VALUE self)
* Complex.rect(1) <=> Complex.rect(1, 1) # => nil # object.imag not zero.
* Complex.rect(1) <=> 'Foo' # => nil # object.imag not defined.
*
+ * \Class \Complex includes module Comparable,
+ * each of whose methods uses Complex#<=> for comparison.
*/
static VALUE
nucomp_cmp(VALUE self, VALUE other)
@@ -1591,16 +1608,15 @@ f_tpositive_p(VALUE x)
}
static VALUE
-f_format(VALUE self, VALUE (*func)(VALUE))
+f_format(VALUE self, VALUE s, VALUE (*func)(VALUE))
{
- VALUE s;
int impos;
get_dat1(self);
impos = f_tpositive_p(dat->imag);
- s = (*func)(dat->real);
+ rb_str_concat(s, (*func)(dat->real));
rb_str_cat2(s, !impos ? "-" : "+");
rb_str_concat(s, (*func)(f_abs(dat->imag)));
@@ -1627,7 +1643,7 @@ f_format(VALUE self, VALUE (*func)(VALUE))
static VALUE
nucomp_to_s(VALUE self)
{
- return f_format(self, rb_String);
+ return f_format(self, rb_usascii_str_new2(""), rb_String);
}
/*
@@ -1649,7 +1665,7 @@ nucomp_inspect(VALUE self)
VALUE s;
s = rb_usascii_str_new2("(");
- rb_str_concat(s, f_format(self, rb_inspect));
+ f_format(self, s, rb_inspect);
rb_str_cat2(s, ")");
return s;
@@ -1715,7 +1731,7 @@ nucomp_loader(VALUE self, VALUE a)
RCOMPLEX_SET_REAL(dat, rb_ivar_get(a, id_i_real));
RCOMPLEX_SET_IMAG(dat, rb_ivar_get(a, id_i_imag));
- OBJ_FREEZE_RAW(self);
+ OBJ_FREEZE(self);
return self;
}
@@ -1763,12 +1779,6 @@ rb_complex_new_polar(VALUE x, VALUE y)
}
VALUE
-rb_complex_polar(VALUE x, VALUE y)
-{
- return rb_complex_new_polar(x, y);
-}
-
-VALUE
rb_Complex(VALUE x, VALUE y)
{
VALUE a[2];
@@ -1793,7 +1803,7 @@ rb_dbl_complex_new(double real, double imag)
* Complex.rect(1, Rational(0, 1)).to_i # => 1
*
* Raises RangeError if <tt>self.imag</tt> is not exactly zero
- * (either <tt>Integer(0)</tt> or <tt>Rational(0, _n_)</tt>).
+ * (either <tt>Integer(0)</tt> or <tt>Rational(0, n)</tt>).
*/
static VALUE
nucomp_to_i(VALUE self)
@@ -1817,7 +1827,7 @@ nucomp_to_i(VALUE self)
* Complex.rect(1, Rational(0, 1)).to_f # => 1.0
*
* Raises RangeError if <tt>self.imag</tt> is not exactly zero
- * (either <tt>Integer(0)</tt> or <tt>Rational(0, _n_)</tt>).
+ * (either <tt>Integer(0)</tt> or <tt>Rational(0, n)</tt>).
*/
static VALUE
nucomp_to_f(VALUE self)
@@ -1839,9 +1849,11 @@ nucomp_to_f(VALUE self)
*
* Complex.rect(1, 0).to_r # => (1/1)
* Complex.rect(1, Rational(0, 1)).to_r # => (1/1)
+ * Complex.rect(1, 0.0).to_r # => (1/1)
*
* Raises RangeError if <tt>self.imag</tt> is not exactly zero
- * (either <tt>Integer(0)</tt> or <tt>Rational(0, _n_)</tt>).
+ * (either <tt>Integer(0)</tt> or <tt>Rational(0, n)</tt>)
+ * and <tt>self.imag.to_r</tt> is not exactly zero.
*
* Related: Complex#rationalize.
*/
@@ -1850,9 +1862,15 @@ nucomp_to_r(VALUE self)
{
get_dat1(self);
- if (!k_exact_zero_p(dat->imag)) {
- rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
- self);
+ if (RB_FLOAT_TYPE_P(dat->imag) && FLOAT_ZERO_P(dat->imag)) {
+ /* Do nothing here */
+ }
+ else if (!k_exact_zero_p(dat->imag)) {
+ VALUE imag = rb_check_convert_type_with_id(dat->imag, T_RATIONAL, "Rational", idTo_r);
+ if (NIL_P(imag) || !k_exact_zero_p(imag)) {
+ rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
+ self);
+ }
}
return f_to_r(dat->real);
}
@@ -1917,21 +1935,6 @@ nucomp_to_c(VALUE self)
/*
* call-seq:
- * to_c -> (0+0i)
- *
- * Returns zero as a Complex:
- *
- * nil.to_c # => (0+0i)
- *
- */
-static VALUE
-nilclass_to_c(VALUE self)
-{
- return rb_complex_new1(INT2FIX(0));
-}
-
-/*
- * call-seq:
* to_c -> complex
*
* Returns +self+ as a Complex object.
@@ -2234,28 +2237,156 @@ string_to_c_strict(VALUE self, int raise)
* call-seq:
* to_c -> complex
*
- * Returns +self+ interpreted as a Complex object;
- * leading whitespace and trailing garbage are ignored:
- *
- * '9'.to_c # => (9+0i)
- * '2.5'.to_c # => (2.5+0i)
- * '2.5/1'.to_c # => ((5/2)+0i)
- * '-3/2'.to_c # => ((-3/2)+0i)
- * '-i'.to_c # => (0-1i)
- * '45i'.to_c # => (0+45i)
- * '3-4i'.to_c # => (3-4i)
- * '-4e2-4e-2i'.to_c # => (-400.0-0.04i)
- * '-0.0-0.0i'.to_c # => (-0.0-0.0i)
- * '1/2+3/4i'.to_c # => ((1/2)+(3/4)*i)
- * '1.0@0'.to_c # => (1+0.0i)
+ * Returns a Complex object:
+ * parses the leading substring of +self+
+ * to extract two numeric values that become the coordinates of the complex object.
+ *
+ * The substring is interpreted as containing
+ * either rectangular coordinates (real and imaginary parts)
+ * or polar coordinates (magnitude and angle parts),
+ * depending on an included or implied "separator" character:
+ *
+ * - <tt>'+'</tt>, <tt>'-'</tt>, or no separator: rectangular coordinates.
+ * - <tt>'@'</tt>: polar coordinates.
+ *
+ * <b>In Brief</b>
+ *
+ * In these examples, we use method Complex#rect to display rectangular coordinates,
+ * and method Complex#polar to display polar coordinates.
+ *
+ * # Rectangular coordinates.
+ *
+ * # Real-only: no separator; imaginary part is zero.
+ * '9'.to_c.rect # => [9, 0] # Integer.
+ * '-9'.to_c.rect # => [-9, 0] # Integer (negative).
+ * '2.5'.to_c.rect # => [2.5, 0] # Float.
+ * '1.23e-14'.to_c.rect # => [1.23e-14, 0] # Float with exponent.
+ * '2.5/1'.to_c.rect # => [(5/2), 0] # Rational.
+ *
+ * # Some things are ignored.
+ * 'foo1'.to_c.rect # => [0, 0] # Unparsed entire substring.
+ * '1foo'.to_c.rect # => [1, 0] # Unparsed trailing substring.
+ * ' 1 '.to_c.rect # => [1, 0] # Leading and trailing whitespace.
+ * *
+ * # Imaginary only: trailing 'i' required; real part is zero.
+ * '9i'.to_c.rect # => [0, 9]
+ * '-9i'.to_c.rect # => [0, -9]
+ * '2.5i'.to_c.rect # => [0, 2.5]
+ * '1.23e-14i'.to_c.rect # => [0, 1.23e-14]
+ * '2.5/1i'.to_c.rect # => [0, (5/2)]
+ *
+ * # Real and imaginary; '+' or '-' separator; trailing 'i' required.
+ * '2+3i'.to_c.rect # => [2, 3]
+ * '-2-3i'.to_c.rect # => [-2, -3]
+ * '2.5+3i'.to_c.rect # => [2.5, 3]
+ * '2.5+3/2i'.to_c.rect # => [2.5, (3/2)]
+ *
+ * # Polar coordinates; '@' separator; magnitude required.
+ * '1.0@0'.to_c.polar # => [1.0, 0.0]
+ * '1.0@'.to_c.polar # => [1.0, 0.0]
+ * "1.0@#{Math::PI}".to_c.polar # => [1.0, 3.141592653589793]
+ * "1.0@#{Math::PI/2}".to_c.polar # => [1.0, 1.5707963267948966]
+ *
+ * <b>Parsed Values</b>
+ *
+ * The parsing may be thought of as searching for numeric literals
+ * embedded in the substring.
+ *
+ * This section shows how the method parses numeric values from leading substrings.
+ * The examples show real-only or imaginary-only parsing;
+ * the parsing is the same for each part.
+ *
+ * '1foo'.to_c # => (1+0i) # Ignores trailing unparsed characters.
+ * ' 1 '.to_c # => (1+0i) # Ignores leading and trailing whitespace.
+ * 'x1'.to_c # => (0+0i) # Finds no leading numeric.
+ *
+ * # Integer literal embedded in the substring.
+ * '1'.to_c # => (1+0i)
+ * '-1'.to_c # => (-1+0i)
+ * '1i'.to_c # => (0+1i)
+ *
+ * # Integer literals that don't work.
+ * '0b100'.to_c # => (0+0i) # Not parsed as binary.
+ * '0o100'.to_c # => (0+0i) # Not parsed as octal.
+ * '0d100'.to_c # => (0+0i) # Not parsed as decimal.
+ * '0x100'.to_c # => (0+0i) # Not parsed as hexadecimal.
+ * '010'.to_c # => (10+0i) # Not parsed as octal.
+ *
+ * # Float literals:
+ * '3.14'.to_c # => (3.14+0i)
+ * '3.14i'.to_c # => (0+3.14i)
+ * '1.23e4'.to_c # => (12300.0+0i)
+ * '1.23e+4'.to_c # => (12300.0+0i)
+ * '1.23e-4'.to_c # => (0.000123+0i)
+ *
+ * # Rational literals:
+ * '1/2'.to_c # => ((1/2)+0i)
+ * '-1/2'.to_c # => ((-1/2)+0i)
+ * '1/2r'.to_c # => ((1/2)+0i)
+ * '-1/2r'.to_c # => ((-1/2)+0i)
+ *
+ * <b>Rectangular Coordinates</b>
+ *
+ * With separator <tt>'+'</tt> or <tt>'-'</tt>,
+ * or with no separator,
+ * interprets the values as rectangular coordinates: real and imaginary.
+ *
+ * With no separator, assigns a single value to either the real or the imaginary part:
+ *
+ * ''.to_c # => (0+0i) # Defaults to zero.
+ * '1'.to_c # => (1+0i) # Real (no trailing 'i').
+ * '1i'.to_c # => (0+1i) # Imaginary (trailing 'i').
+ * 'i'.to_c # => (0+1i) # Special case (imaginary 1).
+ *
+ * With separator <tt>'+'</tt>, both parts positive (or zero):
+ *
+ * # Without trailing 'i'.
+ * '+'.to_c # => (0+0i) # No values: defaults to zero.
+ * '+1'.to_c # => (1+0i) # Value after '+': real only.
+ * '1+'.to_c # => (1+0i) # Value before '+': real only.
+ * '2+1'.to_c # => (2+0i) # Values before and after '+': real and imaginary.
+ * # With trailing 'i'.
+ * '+1i'.to_c # => (0+1i) # Value after '+': imaginary only.
+ * '2+i'.to_c # => (2+1i) # Value before '+': real and imaginary 1.
+ * '2+1i'.to_c # => (2+1i) # Values before and after '+': real and imaginary.
+ *
+ * With separator <tt>'-'</tt>, negative imaginary part:
+ *
+ * # Without trailing 'i'.
+ * '-'.to_c # => (0+0i) # No values: defaults to zero.
+ * '-1'.to_c # => (-1+0i) # Value after '-': negative real, zero imaginary.
+ * '1-'.to_c # => (1+0i) # Value before '-': positive real, zero imaginary.
+ * '2-1'.to_c # => (2+0i) # Values before and after '-': positive real, zero imaginary.
+ * # With trailing 'i'.
+ * '-1i'.to_c # => (0-1i) # Value after '-': negative real, zero imaginary.
+ * '2-i'.to_c # => (2-1i) # Value before '-': positive real, negative imaginary.
+ * '2-1i'.to_c # => (2-1i) # Values before and after '-': positive real, negative imaginary.
+ *
+ * Note that the suffixed character <tt>'i'</tt>
+ * may instead be one of <tt>'I'</tt>, <tt>'j'</tt>, or <tt>'J'</tt>,
+ * with the same effect.
+ *
+ * <b>Polar Coordinates</b>
+ *
+ * With separator <tt>'@'</tt>)
+ * interprets the values as polar coordinates: magnitude and angle.
+ *
+ * '2@'.to_c.polar # => [2, 0.0] # Value before '@': magnitude only.
+ * # Values before and after '@': magnitude and angle.
+ * '2@1'.to_c.polar # => [2.0, 1.0]
* "1.0@#{Math::PI/2}".to_c # => (0.0+1i)
* "1.0@#{Math::PI}".to_c # => (-1+0.0i)
+ * # Magnitude not given: defaults to zero.
+ * '@'.to_c.polar # => [0, 0.0]
+ * '@1'.to_c.polar # => [0, 0.0]
*
- * Returns \Complex zero if the string cannot be converted:
+ * '1.0@0'.to_c # => (1+0.0i)
*
- * 'ruby'.to_c # => (0+0i)
+ * Note that in all cases, the suffixed character <tt>'i'</tt>
+ * may instead be one of <tt>'I'</tt>, <tt>'j'</tt>, <tt>'J'</tt>,
+ * with the same effect.
*
- * See Kernel#Complex.
+ * See {Converting to Non-String}[rdoc-ref:String@Converting+to+Non--5CString].
*/
static VALUE
string_to_c(VALUE self)
@@ -2321,8 +2452,11 @@ nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise)
return a1;
/* should raise exception for consistency */
if (!k_numeric_p(a1)) {
- if (!raise)
- return rb_protect(to_complex, a1, NULL);
+ if (!raise) {
+ a1 = rb_protect(to_complex, a1, NULL);
+ rb_set_errinfo(Qnil);
+ return a1;
+ }
return to_complex(a1);
}
}
@@ -2457,14 +2591,14 @@ float_arg(VALUE self)
*
* The rectangular coordinates of a complex number
* are called the _real_ and _imaginary_ parts;
- * see {Complex number definition}[https://en.wikipedia.org/wiki/Complex_number#Definition].
+ * see {Complex number definition}[https://en.wikipedia.org/wiki/Complex_number#Definition_and_basic_operations].
*
* You can create a \Complex object from rectangular coordinates with:
*
- * - A {complex literal}[rdoc-ref:doc/syntax/literals.rdoc@Complex+Literals].
- * - \Method Complex.rect.
- * - \Method Kernel#Complex, either with numeric arguments or with certain string arguments.
- * - \Method String#to_c, for certain strings.
+ * - A {complex literal}[rdoc-ref:syntax/literals.rdoc@Complex+Literals].
+ * - Method Complex.rect.
+ * - Method Kernel#Complex, either with numeric arguments or with certain string arguments.
+ * - Method String#to_c, for certain strings.
*
* Note that each of the stored parts may be a an instance one of the classes
* Complex, Float, Integer, or Rational;
@@ -2482,7 +2616,7 @@ float_arg(VALUE self)
*
* The polar coordinates of a complex number
* are called the _absolute_ and _argument_ parts;
- * see {Complex polar plane}[https://en.wikipedia.org/wiki/Complex_number#Polar_complex_plane].
+ * see {Complex polar plane}[https://en.wikipedia.org/wiki/Complex_number#Polar_form].
*
* In this class, the argument part
* in expressed {radians}[https://en.wikipedia.org/wiki/Radian]
@@ -2490,9 +2624,9 @@ float_arg(VALUE self)
*
* You can create a \Complex object from polar coordinates with:
*
- * - \Method Complex.polar.
- * - \Method Kernel#Complex, with certain string arguments.
- * - \Method String#to_c, for certain strings.
+ * - Method Complex.polar.
+ * - Method Kernel#Complex, with certain string arguments.
+ * - Method String#to_c, for certain strings.
*
* Note that each of the stored parts may be a an instance one of the classes
* Complex, Float, Integer, or Rational;
@@ -2510,7 +2644,7 @@ float_arg(VALUE self)
*
* First, what's elsewhere:
*
- * - \Class \Complex inherits (directly or indirectly)
+ * - Class \Complex inherits (directly or indirectly)
* from classes {Numeric}[rdoc-ref:Numeric@What-27s+Here]
* and {Object}[rdoc-ref:Object@What-27s+Here].
* - Includes (indirectly) module {Comparable}[rdoc-ref:Comparable@What-27s+Here].
@@ -2576,7 +2710,7 @@ float_arg(VALUE self)
* - #as_json: Returns a serialized hash constructed from +self+.
* - #to_json: Returns a JSON string representing +self+.
*
- * These methods are provided by the {JSON gem}[https://github.com/flori/json]. To make these methods available:
+ * These methods are provided by the {JSON gem}[https://github.com/ruby/json]. To make these methods available:
*
* require 'json/add/complex'
*
@@ -2680,7 +2814,6 @@ Init_Complex(void)
rb_define_method(rb_cComplex, "to_r", nucomp_to_r, 0);
rb_define_method(rb_cComplex, "rationalize", nucomp_rationalize, -1);
rb_define_method(rb_cComplex, "to_c", nucomp_to_c, 0);
- rb_define_method(rb_cNilClass, "to_c", nilclass_to_c, 0);
rb_define_method(rb_cNumeric, "to_c", numeric_to_c, 0);
rb_define_method(rb_cString, "to_c", string_to_c, 0);
@@ -2710,7 +2843,7 @@ Init_Complex(void)
f_complex_new_bang2(rb_cComplex, ZERO, ONE));
#if !USE_FLONUM
- rb_gc_register_mark_object(RFLOAT_0 = DBL2NUM(0.0));
+ rb_vm_register_global_object(RFLOAT_0 = DBL2NUM(0.0));
#endif
rb_provide("complex.so"); /* for backward compatibility */