[DOC] RDoc for Complex (#9181)

This commit is contained in:
Burdette Lamar 2023-12-10 09:22:22 -06:00 committed by GitHub
parent d9dbcd848f
commit 91b0d5fa38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

122
complex.c
View File

@ -523,39 +523,53 @@ static VALUE nucomp_s_convert(int argc, VALUE *argv, VALUE klass);
/* /*
* call-seq: * call-seq:
* Complex(x[, y], exception: true) -> numeric or nil * Complex(abs, arg = 0, exception: true) -> complex or nil
* Complex(s, exception: true) -> complex or nil
* *
* Returns x+i*y; * Returns a new \Complex object if the arguments are valid;
* otherwise raises an exception if +exception+ is +true+;
* otherwise returns +nil+.
* *
* Complex(1, 2) #=> (1+2i) * With Numeric argument +abs+, returns <tt>Complex.rect(abs, arg)</tt> if the arguments are valid.
* Complex('1+2i') #=> (1+2i)
* Complex(nil) #=> TypeError
* Complex(1, nil) #=> TypeError
* *
* Complex(1, nil, exception: false) #=> nil * With string argument +s+, returns a new \Complex object if the argument is valid;
* Complex('1+2', exception: false) #=> nil * the string may have:
* *
* Syntax of string form: * - One or two numeric substrings,
* each of which specifies a Complex, Float, Integer, Numeric, or Rational value,
* specifying {rectangular coordinates}[rdoc-ref:Complex@Rectangular+Coordinates]:
* *
* string form = extra spaces , complex , extra spaces ; * - Sign-separated real and imaginary numeric substrings
* complex = real part | [ sign ] , imaginary part * (with trailing character <tt>'i'</tt>):
* | real part , sign , imaginary part *
* | rational , "@" , rational ; * Complex('1+2i') # => (1+2i)
* real part = rational ; * Complex('+1+2i') # => (1+2i)
* imaginary part = imaginary unit | unsigned rational , imaginary unit ; * Complex('+1-2i') # => (1-2i)
* rational = [ sign ] , unsigned rational ; * Complex('-1+2i') # => (-1+2i)
* unsigned rational = numerator | numerator , "/" , denominator ; * Complex('-1-2i') # => (-1-2i)
* numerator = integer part | fractional part | integer part , fractional part ; *
* denominator = digits ; * - Real-only numeric string (without trailing character <tt>'i'</tt>):
* integer part = digits ; *
* fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ; * Complex('1') # => (1+0i)
* imaginary unit = "i" | "I" | "j" | "J" ; * Complex('+1') # => (1+0i)
* sign = "-" | "+" ; * Complex('-1') # => (-1+0i)
* digits = digit , { digit | "_" , digit }; *
* digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; * - Imaginary-only numeric string (with trailing character <tt>'i'</tt>):
* extra spaces = ? \s* ? ; *
* Complex('1i') # => (0+1i)
* Complex('+1i') # => (0+1i)
* Complex('-1i') # => (0-1i)
*
* - At-sign separated real and imaginary rational substrings,
* each of which specifies a Rational value,
* specifying {polar coordinates}[rdoc-ref:Complex@Polar+Coordinates]:
*
* Complex('1/2@3/4') # => (0.36584443443691045+0.34081938001166706i)
* Complex('+1/2@+3/4') # => (0.36584443443691045+0.34081938001166706i)
* Complex('+1/2@-3/4') # => (0.36584443443691045-0.34081938001166706i)
* Complex('-1/2@+3/4') # => (-0.36584443443691045-0.34081938001166706i)
* Complex('-1/2@-3/4') # => (-0.36584443443691045+0.34081938001166706i)
* *
* See String#to_c.
*/ */
static VALUE static VALUE
nucomp_f_complex(int argc, VALUE *argv, VALUE klass) nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
@ -2350,30 +2364,26 @@ float_arg(VALUE self)
} }
/* /*
* A \Complex object houses a pair of values * A \Complex object houses a pair of values,
* called, respectively, the _real_ and _imaginary_ parts; * given when the object is created as either <i>rectangular coordinates</i>
* see {Complex number}[https://en.wikipedia.org/wiki/Complex_number]. * or <i>polar coordinates</i>.
*
* Note that each of the parts may be a an instance of class Numeric,
* or an instance of one of its subclasses:
* Complex, Float, Integer, or Rational.
*
* You can create a \Complex object with:
*
* - A {complex literal}[rdoc-ref:syntax/literals.rdoc@Complex+Literals].
* - \Method {Kernel#Complex}[https://docs.ruby-lang.org/en/master/Kernel.html#method-i-Complex].
* - Methods Complex.rect or Complex.polar.
* - Methods Numeric#to_c or String#to_c;
* or (trivially) methods Complex#to_c or NilClass#to_c.
* *
* == Rectangular Coordinates * == Rectangular Coordinates
* *
* Each of the methods above (except Complex.polar) takes two "rectangular" arguments * The rectangular coordinates of a complex number
* representing the _real_ and _imaginary_ parts of the created \Complex object; * are called the _real_ and _imaginary_ parts;
* see {Complex definition}[https://en.wikipedia.org/wiki/Complex_number#Definition]. * see {Complex number definition}[https://en.wikipedia.org/wiki/Complex_number#Definition].
* *
* The created object stores the two values, * You can create a \Complex object from rectangular coordinates with:
* which may be retrieved: *
* - 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.
*
* Note that each of the stored parts may be a an instance one of the classes
* Complex, Float, Integer, or Rational;
* they may be retrieved:
* *
* - Separately, with methods Complex#real and Complex#imaginary. * - Separately, with methods Complex#real and Complex#imaginary.
* - Together, with method Complex#rect. * - Together, with method Complex#rect.
@ -2385,13 +2395,19 @@ float_arg(VALUE self)
* *
* == Polar Coordinates * == Polar Coordinates
* *
* \Method Complex.polar takes two "polar" arguments, * The polar coordinates of a complex number
* representing the _modulus_ (or _absolute_) and _argument_ parts * are called the _absolute_ and _argument_ parts;
* of the created \Complex object; * see {Complex polar plane}[https://en.wikipedia.org/wiki/Complex_number#Polar_complex_plane].
* see {Complex plane}[https://en.wikipedia.org/wiki/Complex_number#Polar_complex_plane].
* *
* The created object stores the two values, * You can create a \Complex object from polar coordinates with:
* which may be retrieved: *
* - \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;
* they may be retrieved:
* *
* - Separately, with methods Complex#abs and Complex#arg. * - Separately, with methods Complex#abs and Complex#arg.
* - Together, with method Complex#polar. * - Together, with method Complex#polar.