diff --git a/README.md b/README.md index b6e532a2a..1ba4d0014 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.229.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.230.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.229_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.230_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.229 +Meevax Lisp System, version 0.4.230 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 5fb240097..3e3534c19 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.229 +0.4.230 diff --git a/basis/r7rs.ss b/basis/r7rs.ss index 14ea8ebe2..0be4d47f6 100644 --- a/basis/r7rs.ss +++ b/basis/r7rs.ss @@ -436,13 +436,25 @@ (export finite? infinite? nan? exp log sin cos tan asin acos atan sqrt)) (define-library (scheme complex) - (export make-rectangular - make-polar - real-part - imag-part - angle - ) - ) + (import (meevax complex) + (scheme base) + (scheme inexact)) + + (export make-rectangular make-polar real-part imag-part magnitude angle) + + (begin (define (make-polar magnitude angle) + (make-rectangular (* magnitude (cos angle)) + (* magnitude (sin angle)))) + + (define (magnitude z) + (let ((re (real-part z)) + (im (imag-part z))) + (sqrt (+ (* re re) + (* im im))))) + + (define (angle z) + (atan (imag-part z) + (real-part z))))) (define-library (scheme cxr) (import (meevax pair)) diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index afafdb2ad..bac05f62b 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -436,12 +436,12 @@ inline namespace kernel return apply.at(type_index<2>(x.type(), y.type()))(x, y); } - template - auto inexact_cast(T&& x) -> decltype(auto) + template )> + auto inexact_cast(U&& x) -> decltype(auto) { if constexpr (std::is_same_v, complex>) { - return std::complex(std::forward(x)); + return std::complex(std::forward(x)); } else if constexpr (std::is_floating_point_v>) { @@ -449,7 +449,7 @@ inline namespace kernel } else { - return static_cast(std::forward(x)); + return static_cast(std::forward(x)); } } diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index e3e8ef6f2..f0c5f99b0 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -59,6 +59,31 @@ inline namespace kernel library.export_("char-codepoint"); }); + define_library("(meevax complex)", [](library & library) + { + library.define("make-rectangular", [](let const& xs) + { + assert(apply(car(xs))); + assert(apply(cadr(xs))); + + return make(car(xs), cadr(xs)); + }); + + library.define("real-part", [](let const& xs) + { + return car(xs).as().real(); + }); + + library.define("imag-part", [](let const& xs) + { + return car(xs).as().imag(); + }); + + library.export_("make-rectangular"); + library.export_("real-part"); + library.export_("imag-part"); + }); + define_library("(meevax context)", [](library & library) { library.define("emergency-exit", [](let const& xs) diff --git a/src/main.cpp b/src/main.cpp index f527bca40..89f9d6682 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,7 @@ auto main(int const argc, char const* const* const argv) -> int main.display_version(); main.import_("(scheme base)"); main.import_("(scheme char)"); + main.import_("(scheme complex)"); main.import_("(scheme cxr)"); main.import_("(scheme eval)"); main.import_("(scheme inexact)");