Skip to content

Commit

Permalink
Cleanup some macro definitions
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 8, 2024
1 parent dbbd079 commit 2eb1bff
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 53 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.281.so` and executable `meevax`.
| `all` | Build shared-library `libmeevax.0.5.282.so` and executable `meevax`.
| `install` | Copy files into `/usr/local` directly.
| `package` | Generate debian package `meevax_0.5.281_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.281_amd64.deb`.
| `package` | Generate debian package `meevax_0.5.282_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.282_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.281
0.5.282
6 changes: 3 additions & 3 deletions include/meevax/kernel/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ inline namespace number

auto lcm(object const&, object const&) -> object;

auto sqrt(object const&) -> object;
auto square_root(object const&) -> object;

auto pow(object const&, object const&) -> object;

Expand All @@ -347,9 +347,9 @@ inline namespace number

auto floor(object const&) -> object;

auto ceil(object const&) -> object;
auto ceiling(object const&) -> object;

auto trunc(object const&) -> object;
auto truncate(object const&) -> object;

auto round(object const&) -> object;

Expand Down
6 changes: 3 additions & 3 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ namespace meevax::inline kernel

library.define<procedure>("sqrt", [](let const& xs)
{
return sqrt(car(xs));
return square_root(car(xs));
});

library.define<procedure>("log", [](let const& xs)
Expand Down Expand Up @@ -1101,12 +1101,12 @@ namespace meevax::inline kernel

library.define<procedure>("ceiling", [](let const& xs)
{
return ceil(car(xs));
return ceiling(car(xs));
});

library.define<procedure>("truncate", [](let const& xs)
{
return trunc(car(xs));
return truncate(car(xs));
});

library.define<procedure>("round", [](let const& xs)
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace meevax::inline kernel
{
auto hypotenuse = [](let const& x, let const& y)
{
return sqrt(x * x + y * y);
return square_root(x * x + y * y);
};

return hypotenuse(real_part(x),
Expand Down
88 changes: 45 additions & 43 deletions src/kernel/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ inline namespace number
}
else if constexpr (std::is_same_v<T, complex>)
{
return sqrt(x.real() * x.real() + x.imag() * x.imag());
return square_root(x.real() * x.real() + x.imag() * x.imag());
}
else
{
Expand All @@ -771,7 +771,7 @@ inline namespace number

auto quotient(object const& x, object const& y) -> object
{
return trunc(x / y);
return truncate(x / y);
}

auto remainder(object const& x, object const& y) -> object
Expand All @@ -794,7 +794,7 @@ inline namespace number
return abs(quotient(x * y, gcd(x, y)));
}

auto sqrt(object const& x) -> object
auto square_root(object const& x) -> object
{
auto f = []<typename T>(T const& x)
{
Expand All @@ -807,7 +807,7 @@ inline namespace number
}
else
{
auto sqrt = [](auto&& x)
auto square_root = [](auto const& x)
{
if constexpr (std::is_same_v<T, exact_integer>)
{
Expand All @@ -817,12 +817,12 @@ inline namespace number
}
else
{
return make(std::sqrt(static_cast<double>(std::forward<decltype(x)>(x))));
return make(std::sqrt(static_cast<double>(x)));
}
};

return x < exact_integer(0) ? make<complex>(e0, sqrt(exact_integer(0) - x))
: sqrt(x);
return x < exact_integer(0) ? make<complex>(e0, square_root(exact_integer(0) - x))
: square_root(x);
}
};

Expand Down Expand Up @@ -907,73 +907,75 @@ inline namespace number
}
}

#define DEFINE(ROUND) \
auto ROUND(object const& x) -> object \
#define DEFINE_EXACTNESS_PRESERVED_COMPLEX1(NAME, CMATH) \
auto NAME(object const& x) -> object \
{ \
auto f = []<typename T>(T const& x) \
{ \
if constexpr (std::is_floating_point_v<T>) \
{ \
return std::ROUND(std::forward<decltype(x)>(x)); \
return CMATH(x); \
} \
else if constexpr (std::is_same_v<T, ratio>) \
{ \
return exact_integer(std::ROUND(static_cast<double>(std::forward<decltype(x)>(x)))); \
return exact_integer(CMATH(static_cast<double>(x))); \
} \
else if constexpr (std::is_same_v<T, exact_integer>) \
{ \
return std::forward<decltype(x)>(x); \
return x; \
} \
else \
{ \
return complex(ROUND(x.real()), \
ROUND(x.imag())); \
return complex(NAME(x.real()), \
NAME(x.imag())); \
} \
}; \
\
return apply_to<complex_number>(f, x); \
} \
static_assert(true)

DEFINE(floor);
DEFINE(ceil);
DEFINE(trunc);
DEFINE(round);
}

#undef DEFINE
DEFINE_EXACTNESS_PRESERVED_COMPLEX1(ceiling, std::ceil)
DEFINE_EXACTNESS_PRESERVED_COMPLEX1(floor, std::floor)
DEFINE_EXACTNESS_PRESERVED_COMPLEX1(round, std::round)
DEFINE_EXACTNESS_PRESERVED_COMPLEX1(truncate, std::trunc)

#define DEFINE(CMATH) \
auto CMATH(object const& x) -> object \
#define DEFINE_COMPLEX1(NAME, CMATH) \
auto NAME(object const& x) -> object \
{ \
auto f = []<typename T>(T const& x) \
{ \
if constexpr (std::is_same_v<T, complex>) \
{ \
auto const z = std::CMATH(static_cast<std::complex<double>>(std::forward<decltype(x)>(x))); \
auto const z = CMATH(static_cast<std::complex<double>>(std::forward<decltype(x)>(x))); \
\
return complex(make(z.real()), \
make(z.imag())); \
} \
else \
{ \
return std::CMATH(static_cast<double>(std::forward<decltype(x)>(x))); \
return CMATH(static_cast<double>(std::forward<decltype(x)>(x))); \
} \
}; \
\
return apply_to<complex_number>(f, x); \
} \
static_assert(true)

DEFINE(sin); DEFINE(asin); DEFINE(sinh); DEFINE(asinh);
DEFINE(cos); DEFINE(acos); DEFINE(cosh); DEFINE(acosh);
DEFINE(tan); DEFINE(atan); DEFINE(tanh); DEFINE(atanh);

DEFINE(exp);
DEFINE(log);

#undef DEFINE
}

#define DEFINE_REAL_UNARY(NAME, CMATH) \
DEFINE_COMPLEX1(acos, std::acos)
DEFINE_COMPLEX1(acosh, std::acosh)
DEFINE_COMPLEX1(asin, std::asin)
DEFINE_COMPLEX1(asinh, std::asinh)
DEFINE_COMPLEX1(atan, std::atan)
DEFINE_COMPLEX1(atanh, std::atanh)
DEFINE_COMPLEX1(cos, std::cos)
DEFINE_COMPLEX1(cosh, std::cosh)
DEFINE_COMPLEX1(exp, std::exp)
DEFINE_COMPLEX1(log, std::log)
DEFINE_COMPLEX1(sin, std::sin)
DEFINE_COMPLEX1(sinh, std::sinh)
DEFINE_COMPLEX1(tan, std::tan)
DEFINE_COMPLEX1(tanh, std::tanh)

#define DEFINE_REAL1(NAME, CMATH) \
auto NAME(object const& x) -> object \
{ \
auto f = [](auto&& x) \
Expand All @@ -984,9 +986,9 @@ inline namespace number
return apply_to<real_number>(f, x); \
}

DEFINE_REAL_UNARY(gamma, std::tgamma)
DEFINE_REAL1(gamma, std::tgamma)

#define DEFINE_REAL_BINARY(NAME, CMATH) \
#define DEFINE_REAL2(NAME, CMATH) \
auto NAME(object const& x, object const& y) -> object \
{ \
auto f = [](auto&& x, auto&& y) \
Expand All @@ -998,9 +1000,9 @@ inline namespace number
return apply_to<real_numbers>(f, x, y); \
}

DEFINE_REAL_BINARY(atan, std::atan2)
DEFINE_REAL_BINARY(copy_sign, std::copysign)
DEFINE_REAL_BINARY(next_after, std::nextafter)
DEFINE_REAL2(atan, std::atan2)
DEFINE_REAL2(copy_sign, std::copysign)
DEFINE_REAL2(next_after, std::nextafter)

auto load_exponent(object const& x, object const& y) -> object
{
Expand Down

0 comments on commit 2eb1bff

Please sign in to comment.