diff --git a/README.md b/README.md index 1ba4d0014..faf473275 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.230.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.231.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.230_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.231_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.230 +Meevax Lisp System, version 0.4.231 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 3e3534c19..5942fea1a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.230 +0.4.231 diff --git a/include/meevax/kernel/complex.hpp b/include/meevax/kernel/complex.hpp index c08ff3c56..6c6698342 100644 --- a/include/meevax/kernel/complex.hpp +++ b/include/meevax/kernel/complex.hpp @@ -37,8 +37,6 @@ inline namespace kernel auto imag() const noexcept -> const_reference; - static auto pattern() -> std::regex const&; - auto real() const noexcept -> const_reference; explicit operator std::complex(); diff --git a/src/kernel/complex.cpp b/src/kernel/complex.cpp index 30c17d3ae..e571547c7 100644 --- a/src/kernel/complex.cpp +++ b/src/kernel/complex.cpp @@ -23,10 +23,22 @@ inline namespace kernel { complex::complex(std::string const& token, int radix) { - if (std::smatch result; std::regex_match(token, result, pattern())) + std::regex static const rectangular { R"(([+-]?.*)([+-].*)i)" }; + + std::regex static const polar { R"(([+-]?.*)@([+-]?.*))" }; + + if (std::smatch result; std::regex_match(token, result, rectangular)) + { + std::get<0>(*this) = string_to_real(result[1].length() == 0 ? "0" : result.str(1), radix); + std::get<1>(*this) = string_to_real(result[2].length() == 1 ? result.str(2) + "1" : result.str(2), radix); + } + else if (std::regex_match(token, result, polar)) { - std::get<0>(*this) = string_to_real(result.str(1), radix); - std::get<1>(*this) = string_to_real(result.str(2), radix); + auto const magnitude = string_to_real(result.str(1), radix); + auto const angle = string_to_real(result.str(2), radix); + + std::get<0>(*this) = magnitude * apply(angle); + std::get<1>(*this) = magnitude * apply(angle); } else { @@ -51,12 +63,6 @@ inline namespace kernel return second; } - auto complex::pattern() -> std::regex const& - { - std::regex static const pattern { R"(([+-]?.*)([+-].*)[ij])" }; - return pattern; - } - auto complex::real() const noexcept -> const_reference { return first; diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index d0f102538..126ad3649 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -217,7 +217,7 @@ inline namespace kernel auto operator * (complex const& a, complex const& b) -> complex { return complex(a.real() * b.real() - a.imag() * b.imag(), a.imag() * b.real() + a.real() * b.imag()); } auto operator / (complex const& a, complex const& b) -> complex { auto x = a.real() * b.real() + a.imag() * b.imag(); auto y = a.imag() * b.real() - a.real() * b.imag(); auto d = b.real() * b.real() + b.imag() * b.imag(); return complex(x / d, y / d); } auto operator % (complex const& , complex const& ) -> complex { throw std::invalid_argument("unsupported operation"); } - auto operator ==(complex const& a, complex const& b) -> bool { return apply(a.real(), b.real()) and apply(a.imag(), b.imag()); } + auto operator ==(complex const& a, complex const& b) -> bool { return apply(a.real(), b.real()).as() and apply(a.imag(), b.imag()).as(); } auto operator !=(complex const& a, complex const& b) -> bool { return not (a == b); } auto operator < (complex const& , complex const& ) -> bool { throw std::invalid_argument("unsupported operation"); } auto operator <=(complex const& , complex const& ) -> bool { throw std::invalid_argument("unsupported operation"); } diff --git a/test/r7rs.ss b/test/r7rs.ss index ced304e7c..3b59e0e64 100644 --- a/test/r7rs.ss +++ b/test/r7rs.ss @@ -982,7 +982,7 @@ (check (sqrt 9) => 3) -; (check (sqrt -1) => +i) +(check (sqrt -1) => +i) ; (check (exact-integer-sqrt 4) => #,(values 2 0)) @@ -1555,4 +1555,4 @@ (check-report) -(exit (check-passed? 391)) +(exit (check-passed? 392))