Skip to content

Commit

Permalink
Add procedures binary64-max and binary64-min
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Dec 11, 2024
1 parent c854f59 commit 0208039
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.288
0.5.289
13 changes: 10 additions & 3 deletions basis/srfi-144.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
;
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -245,5 +248,9 @@
(define flnormalized? binary64-normalized?)

(define fldenormalized? binary64-denormalized?)

(define flmax binary64-max)

(define flmin binary64-min)
)
)
4 changes: 0 additions & 4 deletions include/meevax/kernel/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 42 additions & 4 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ namespace meevax::inline kernel
return std::numeric_limits<double>::is_iec559 and car(xs).is<double>();
});

library.define<double>("binary64-min", std::numeric_limits<double>::min());
library.define<double>("binary64-least", std::numeric_limits<double>::min());

library.define<double>("binary64-max", std::numeric_limits<double>::max());
library.define<double>("binary64-greatest", std::numeric_limits<double>::max());

library.define<double>("binary64-epsilon", std::numeric_limits<double>::epsilon());

Expand Down Expand Up @@ -646,6 +646,30 @@ namespace meevax::inline kernel
{
return std::fpclassify(car(xs).as<double>()) == FP_SUBNORMAL;
});

library.define<procedure>("binary64-max", [](let const& xs)
{
auto max = -std::numeric_limits<double>::infinity();

for (let const& x : xs)
{
max = std::fmax(max, x.as<double>());
}

return make(max);
});

library.define<procedure>("binary64-min", [](let const& xs)
{
auto min = std::numeric_limits<double>::infinity();

for (let const& x : xs)
{
min = std::fmin(min, x.as<double>());
}

return make(min);
});
});

define<library>("(meevax list)", [](library & library)
Expand Down Expand Up @@ -1045,12 +1069,26 @@ namespace meevax::inline kernel

library.define<procedure>("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<procedure>("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<procedure>("+", [](let const& xs)
Expand Down
24 changes: 0 additions & 24 deletions src/kernel/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []<typename T>(T const& x)
Expand Down
14 changes: 13 additions & 1 deletion test/srfi-144.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 0208039

Please sign in to comment.