Skip to content

Commit

Permalink
Add new free function is_exact
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Oct 2, 2023
1 parent 87f2218 commit fec8935
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.5_amd64.deb
sudo apt install build/meevax_0.5.6_amd64.deb
```

or
Expand Down Expand Up @@ -131,9 +131,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.5.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.6.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.5_amd64.deb`
| `package` | Generate debian package `meevax_0.5.6_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.5
0.5.6
27 changes: 25 additions & 2 deletions basis/r4rs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,33 @@
(only (meevax continuation) call-with-current-continuation)
(prefix (only (meevax environment) load) %)
(only (meevax function) procedure?)
(meevax inexact)
(only (meevax inexact) exp log sqrt sin cos tan asin acos atan)
(meevax list)
(only (meevax macro-transformer) er-macro-transformer identifier?)
(meevax number)
(only (meevax number)
number?
complex?
real?
rational?
integer?
= < > <= >=
+ * - /
abs
% ; deprecated
ratio-numerator ; deprecated
ratio-denominator ; deprecated
floor ceiling truncate round
expt
exact inexact
string->number

; to be removed
exact-integer? ; r7rs
imaginary?
ratio?
single-float?
double-float?
)
(meevax pair)
(meevax port)
(prefix (meevax read) %)
Expand Down
2 changes: 2 additions & 0 deletions include/meevax/kernel/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ inline namespace number

auto is_integer(object const&) -> bool;

auto is_exact(object const&) -> bool;

auto is_finite(object const&) -> bool;

auto is_infinite(object const&) -> bool;
Expand Down
14 changes: 14 additions & 0 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,26 +540,35 @@ inline namespace kernel
return is_integer(xs[0]);
});

library.define<predicate>("exact?", [](let const& xs)
{
return is_exact(xs[0]);
});

library.define<predicate>("exact-integer?", [](let const& xs)
{
return xs[0].is<exact_integer>();
});

// TODO REMOVE
library.define<predicate>("imaginary?", [](let const& xs)
{
return xs[0].is<complex>();
});

// TODO REMOVE
library.define<predicate>("ratio?", [](let const& xs)
{
return xs[0].is<ratio>();
});

// TODO REMOVE
library.define<predicate>("single-float?", [](let const& xs)
{
return xs[0].is<float>();
});

// TODO REMOVE
library.define<predicate>("double-float?", [](let const& xs)
{
return xs[0].is<double>();
Expand Down Expand Up @@ -624,6 +633,7 @@ inline namespace kernel
}
});

// TODO RENAME
library.define<function>("%", [](let const& xs)
{
return xs[0] % xs[1];
Expand All @@ -634,6 +644,10 @@ inline namespace kernel
return abs(xs[0]);
});

// TODO QUOTIENT
// TODO REMAINDER
// TODO MODULO

library.define<function>("ratio-numerator", [](let const& xs)
{
return make(xs[0].as<ratio>().numerator());
Expand Down
19 changes: 19 additions & 0 deletions src/kernel/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,25 @@ inline namespace number
return test(f, x);
}

auto is_exact(object const& x) -> bool
{
auto f = [](auto const& x)
{
using T = std::decay_t<decltype(x)>;

if constexpr (std::is_same_v<T, complex>)
{
return is_exact(x.real()) and is_exact(x.imag());
}
else
{
return std::is_same_v<T, ratio> or std::is_same_v<T, exact_integer>;
}
};

return test(f, x);
}

auto is_finite(object const& x) -> bool
{
return not is_infinite(x);
Expand Down

0 comments on commit fec8935

Please sign in to comment.