diff --git a/README.md b/README.md index dde5dd590..c86ad34d1 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,9 @@ Then, select one of the following targets and `make` it according to your purpos | Target | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.288.so` and executable `meevax`. +| `all` | Build shared-library `libmeevax.0.5.289.so` and executable `meevax`. | `install` | Copy files into `/usr/local` directly. -| `package` | Generate debian package `meevax_0.5.288_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.288_amd64.deb`. +| `package` | Generate debian package `meevax_0.5.289_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.289_amd64.deb`. | `test` | Test executable `meevax`. This target requires Valgrind to be installed. | `uninstall` | Remove files copied to `/usr/local` directly by target `install`. diff --git a/VERSION b/VERSION index f8dc1ad47..f4db1a910 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.288 +0.5.289 diff --git a/basis/srfi-144.ss b/basis/srfi-144.ss index 11a2eb6ad..0955b4157 100644 --- a/basis/srfi-144.ss +++ b/basis/srfi-144.ss @@ -5,8 +5,10 @@ binary64-epsilon binary64-exponent binary64-fractional-part + binary64-greatest binary64-integer-log-binary binary64-integral-part + binary64-least binary64-log-binary binary64-max binary64-min @@ -77,7 +79,8 @@ flpositive? flnegative? flodd? fleven? flfinite? flinfinite? flnan? flnormalized? fldenormalized? - ; flmax flmin fl+ fl* fl+* fl- fl/ flabs flabsdiff + flmax flmin + ; fl+ fl* fl+* fl- fl/ flabs flabsdiff ; flposdiff flsgn flnumerator fldenominator ; flfloor flceiling flround fltruncate ; @@ -171,9 +174,9 @@ (define fl-gamma-2/3 (gamma (/ 2 3))) - (define fl-greatest binary64-max) + (define fl-greatest binary64-greatest) - (define fl-least binary64-min) + (define fl-least binary64-least) (define fl-epsilon binary64-epsilon) @@ -245,5 +248,9 @@ (define flnormalized? binary64-normalized?) (define fldenormalized? binary64-denormalized?) + + (define flmax binary64-max) + + (define flmin binary64-min) ) ) diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 6e0eb3cc8..d81ae4fe7 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -321,10 +321,6 @@ inline namespace number auto is_even(object const&) -> bool; - auto max(object const&) -> object; - - auto min(object const&) -> object; - auto abs(object const&) -> object; auto quotient(object const&, object const&) -> object; diff --git a/src/kernel/boot.cpp b/src/kernel/boot.cpp index c34ed991a..bd3f59aba 100644 --- a/src/kernel/boot.cpp +++ b/src/kernel/boot.cpp @@ -584,9 +584,9 @@ namespace meevax::inline kernel return std::numeric_limits::is_iec559 and car(xs).is(); }); - library.define("binary64-min", std::numeric_limits::min()); + library.define("binary64-least", std::numeric_limits::min()); - library.define("binary64-max", std::numeric_limits::max()); + library.define("binary64-greatest", std::numeric_limits::max()); library.define("binary64-epsilon", std::numeric_limits::epsilon()); @@ -646,6 +646,30 @@ namespace meevax::inline kernel { return std::fpclassify(car(xs).as()) == FP_SUBNORMAL; }); + + library.define("binary64-max", [](let const& xs) + { + auto max = -std::numeric_limits::infinity(); + + for (let const& x : xs) + { + max = std::fmax(max, x.as()); + } + + return make(max); + }); + + library.define("binary64-min", [](let const& xs) + { + auto min = std::numeric_limits::infinity(); + + for (let const& x : xs) + { + min = std::fmin(min, x.as()); + } + + return make(min); + }); }); define("(meevax list)", [](library & library) @@ -1045,12 +1069,26 @@ namespace meevax::inline kernel library.define("max", [](let const& xs) { - return max(xs); + if (auto iter = std::max_element(xs.begin(), xs.end(), less_than); iter != xs.end()) + { + return std::any_of(xs.begin(), xs.end(), is_inexact) ? inexact(*iter) : *iter; + } + else + { + return unspecified; + } }); library.define("min", [](let const& xs) { - return min(xs); + if (auto iter = std::min_element(xs.begin(), xs.end(), less_than); iter != xs.end()) + { + return std::any_of(xs.begin(), xs.end(), is_inexact) ? inexact(*iter) : *iter; + } + else + { + return unspecified; + } }); library.define("+", [](let const& xs) diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index 3c8b4d85d..8d56b547c 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -717,30 +717,6 @@ inline namespace number return is_zero(remainder(x, e2)); } - auto max(object const& xs) -> object - { - if (auto iter = std::max_element(xs.begin(), xs.end(), less_than); iter != xs.end()) - { - return std::any_of(xs.begin(), xs.end(), is_inexact) ? inexact(*iter) : *iter; - } - else - { - return unspecified; - } - } - - auto min(object const& xs) -> object - { - if (auto iter = std::min_element(xs.begin(), xs.end(), less_than); iter != xs.end()) - { - return std::any_of(xs.begin(), xs.end(), is_inexact) ? inexact(*iter) : *iter; - } - else - { - return unspecified; - } - } - auto abs(object const& x) -> object { auto f = [](T const& x) diff --git a/test/srfi-144.ss b/test/srfi-144.ss index 72636d812..961188739 100644 --- a/test/srfi-144.ss +++ b/test/srfi-144.ss @@ -187,6 +187,18 @@ (check (fldenormalized? (/ fl-least 2)) => #t) +(check (flmax) => -inf.0) + +(check (flmax 0.0) => 0.0) + +(check (flmax -1.0 0.0 1.0) => 1.0) + +(check (flmin) => +inf.0) + +(check (flmin 0.0) => 0.0) + +(check (flmin -1.0 0.0 1.0) => -1.0) + (check-report) -(exit (check-passed? 90)) +(exit (check-passed? 96))