24 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 676ab238a2 mruby-complex: add parentheses to Math method calls
added parentheses to Math.hypot and Math.atan2 calls where the return
value is used.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:08 +09:00
Yukihiro "Matz" Matsumoto 01e008167b mruby-complex: add comprehensive call-seq documentation for Complex methods
Added complete call-seq documentation for all Complex methods in
mrblib/complex.rb (18 methods):

## Complex Class Methods:

- polar: creates complex number from polar coordinates (magnitude, angle)
  with trigonometric conversion using Math.cos and Math.sin

## Complex Instance Methods:

- inspect, to_s: string representation methods for debugging and display
  with proper formatting of real and imaginary parts

- +@, -@: unary plus and minus operators for identity and negation

- <=>: spaceship operator for comparison with other numeric types,
  enables Comparable module functionality with proper nil handling

- abs/magnitude: absolute value (magnitude) calculation using hypot
- abs2: square of absolute value for performance-critical calculations
- arg/angle/phase: argument (angle) calculation using atan2

- conjugate/conj: complex conjugate operation (negates imaginary part)
- fdiv: floating-point division ensuring float results
- polar: returns [magnitude, angle] array representation
- real?: always returns false for complex numbers
- rectangular/rect: returns [real, imaginary] array representation

- to_c: returns self (identity conversion)
- to_r: converts to rational when imaginary part is zero, raises RangeError otherwise

## Numeric Extension Methods:

- i: creates pure imaginary number (0+num*i) for convenient complex creation
- to_c: converts any numeric to complex with zero imaginary part

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:45 +09:00
Yukihiro "Matz" Matsumoto 75de002058 mruby-complex: provide Complex#<=> in Ruby 2024-06-17 08:14:27 +09:00
fn ⌃ ⌥ c65200cb5a complex.rb: implement Numeric#to_c 2022-10-24 17:31:52 -07:00
Yukihiro "Matz" Matsumoto 49f75703cc complex.rb: unary plus (+@) to return self avoiding copying. 2021-03-24 11:06:48 +09:00
Yukihiro "Matz" Matsumoto 9ed212ef9e complex.c: implement Complex addition and subtraction in C. 2021-03-24 11:06:14 +09:00
Yukihiro "Matz" Matsumoto 3deb62d653 complex.c: implement Complex#/ and #quo in C. 2021-03-24 10:27:49 +09:00
Yukihiro "Matz" Matsumoto 5573707d7f complex.c: implement Complex#* in C. 2021-03-24 09:53:39 +09:00
Yukihiro "Matz" Matsumoto dc5d74dda8 rational.rb: avoid 'NaNi` representation.
Use `NaN*i` as CRuby does.
2021-03-24 09:52:15 +09:00
Yukihiro "Matz" Matsumoto 73056aeb2b complex.c: define Complex#== in C.
This change also fixes the error caused by `rational.c` that calls
`mrb_complex_eq()`, which had been undefined.
2021-03-21 08:30:52 +09:00
Yukihiro "Matz" Matsumoto d3184e4a6d complex.c: overhaul complex operators.
- define `MRB_TT_COMPLEX`
- change object structure (`struct RComplex`)
- add memory management for `MRB_TT_COMPLEX`
- avoid operator overloading as much as possible
- as a result, performance improved a log
- should work with and without `Rational` defined
2021-03-19 10:37:10 +09:00
Yukihiro "Matz" Matsumoto c6149370b0 Refactor method overriding.
* Use `class_eval` instead of `instance_eval`.
* Reduce `class_eval` calls
* define `Numeric#i`
* undefine `Complex#i`
2021-02-05 21:54:11 +09:00
Yukihiro "Matz" Matsumoto 7ce03e32b7 Add Complex#to_c method. 2021-02-05 21:42:42 +09:00
dearblue 80fe9838d2 Integrate Fixnum class into Integer class
* The `Fixnum` constant is now an alias for the `Integer` class.
* Remove `struct mrb_state::fixnum_class` member.
  If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12 16:21:44 +09:00
Yukihiro "Matz" Matsumoto 2ffb77586a Symbolify saved alias name to improve performance. 2020-06-20 12:07:49 +09:00
KOBAYASHI Shuji 4bdb1eb5aa Drop dependencies from mruby-complex to some gems 2019-12-15 22:51:07 +09:00
Ray Chason 1cd0ff0d42 Avoid overflow and underflow in Complex#/ 2019-08-09 00:08:36 -04:00
Ray Chason c181d1e7fa Implement Complex#abs in terms of Math.hypot
Math.hypot avoids premature overflow and underflow
2019-08-08 23:59:25 -04:00
Yukihiro "Matz" Matsumoto 2a410c0e1b Avoid making top-level env in initialization code; ref #4581 2019-07-18 00:34:08 +09:00
Yukihiro "Matz" Matsumoto 4261ba9443 Remove some overhead from methods defined in Ruby in Complex. 2019-05-26 09:19:29 +09:00
Yukihiro "Matz" Matsumoto fccec8964a Implements part of Complex class in C. 2019-05-21 21:08:26 +09:00
KOBAYASHI Shuji 6c9c189e4b Move Object#(Rational|Complex) to Kernel 2019-05-18 18:31:55 +09:00
Ukrainskiy Sergey d67d2ae8e8 Basic implementation of Complex and Rational classes 2019-05-15 16:57:21 +09:00
Ukrainskiy Sergey 8808219e6d Initial suffix support 2019-05-15 16:57:21 +09:00