14 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto ee4d349f2e mruby-complex: implement Complex#** in C
Implement the Complex#** method in C. This method calculates complex
exponentiation using `exp(w * log(z))` for complex exponents and
`(abs(z)**n) * Complex.polar(1, n * arg(z))` for real exponents.
2025-08-16 12:03:12 +09:00
Yukihiro "Matz" Matsumoto c3610fdab2 mruby-complex: add test for division by zero
Add a test case to ensure that dividing a complex number by
`Complex(0, 0)` raises a `ZeroDivisionError`.

Co-authored-by: Gemini <gemini@google.com>
2025-08-16 09:03:52 +09:00
Yukihiro "Matz" Matsumoto 01a8edea35 complex.rb: add test for arithmetic operators. [ci skip]
Tests for (`Float` or `Integer`) `op` `Complex`. Also added test
dependency to `mruby-rational` since `int_div` definition relies on
`Rational` when `MRB_USE_RATIONAL` is defined.
2021-03-26 17:20:25 +09:00
Yukihiro "Matz" Matsumoto ed32b6fcdc Update tests for integer division. 2020-10-12 16:21:43 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +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
KOBAYASHI Shuji 44381f0a0c Refine message to skip in nested assert
- I think "Info" is used only to `skip`, so change to "Skip".
- Changed the default value of `assert` and specify the argument explicitly
  at the caller of `assert` because it is unnatural "Assertion failed" is
  output even though the assertion doesn't fail.

== Example:

  def assert_foo(exp, act)
    assert do
      assert_equal exp[0], act[0]
      assert_equal exp[1], act[1]
    end
  end

  def assert_bar(exp, act)
    assert do
      skip
    end
  end

  def assert_baz(exp, act)
    assert do
      assert_equal exp, act
      assert_bar exp, act
    end
  end

  assert 'test#skip_in_nested_assert' do
    assert_baz 1, 1
  end

  === Before this patch:

    ?..
    Info: test#skip_in_nested_assert (core)
     - Assertion[1]
        Info: Assertion failed (core)
         - Assertion[1-2]
            Skip: Assertion failed (core)
      Total: 3
         OK: 2
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 1

  === After this patch:

    ???
    Skip: test#skip_in_nested_assert (core)
     - Assertion[1]
        Skip: assert (core)
         - Assertion[1-2]
            Skip: assert (core)
      Total: 3
         OK: 0
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 3
2019-07-30 13:05:01 +09:00
Yukihiro "Matz" Matsumoto a9fd2e6464 Resolve ambiguous argument warning. 2019-07-13 13:16:30 +09:00
dearblue a215292b6a Use nested assert 2019-06-29 11:54:17 +09:00
KOBAYASHI Shuji 48903850e9 Freeze Rational and Complex objects 2019-05-23 13:40:49 +09:00
Yukihiro "Matz" Matsumoto f6e4145ad9 Remove Complex(string) complex generation.
It should raise an error.
2019-05-21 21:08:26 +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