From 2eb1bff668f82b0a003e7617a430122ed1a5d17d Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 8 Dec 2024 12:42:01 +0900 Subject: [PATCH] Cleanup some macro definitions Signed-off-by: yamacir-kit --- README.md | 4 +- VERSION | 2 +- include/meevax/kernel/number.hpp | 6 +-- src/kernel/boot.cpp | 6 +-- src/kernel/complex.cpp | 2 +- src/kernel/number.cpp | 88 ++++++++++++++++---------------- 6 files changed, 55 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 821b3d45d..31c2f4606 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.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`. diff --git a/VERSION b/VERSION index 57765b94b..7ba845667 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.281 +0.5.282 diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 06c42c24b..a59bad800 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -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; @@ -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; diff --git a/src/kernel/boot.cpp b/src/kernel/boot.cpp index 6b243390d..d4f404d92 100644 --- a/src/kernel/boot.cpp +++ b/src/kernel/boot.cpp @@ -462,7 +462,7 @@ namespace meevax::inline kernel library.define("sqrt", [](let const& xs) { - return sqrt(car(xs)); + return square_root(car(xs)); }); library.define("log", [](let const& xs) @@ -1101,12 +1101,12 @@ namespace meevax::inline kernel library.define("ceiling", [](let const& xs) { - return ceil(car(xs)); + return ceiling(car(xs)); }); library.define("truncate", [](let const& xs) { - return trunc(car(xs)); + return truncate(car(xs)); }); library.define("round", [](let const& xs) diff --git a/src/kernel/complex.cpp b/src/kernel/complex.cpp index 3267c12dd..6a815baad 100644 --- a/src/kernel/complex.cpp +++ b/src/kernel/complex.cpp @@ -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), diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index 00675b76d..3ee7958ca 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -757,7 +757,7 @@ inline namespace number } else if constexpr (std::is_same_v) { - return sqrt(x.real() * x.real() + x.imag() * x.imag()); + return square_root(x.real() * x.real() + x.imag() * x.imag()); } else { @@ -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 @@ -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 = [](T const& x) { @@ -807,7 +807,7 @@ inline namespace number } else { - auto sqrt = [](auto&& x) + auto square_root = [](auto const& x) { if constexpr (std::is_same_v) { @@ -817,12 +817,12 @@ inline namespace number } else { - return make(std::sqrt(static_cast(std::forward(x)))); + return make(std::sqrt(static_cast(x))); } }; - return x < exact_integer(0) ? make(e0, sqrt(exact_integer(0) - x)) - : sqrt(x); + return x < exact_integer(0) ? make(e0, square_root(exact_integer(0) - x)) + : square_root(x); } }; @@ -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 = [](T const& x) \ { \ if constexpr (std::is_floating_point_v) \ { \ - return std::ROUND(std::forward(x)); \ + return CMATH(x); \ } \ else if constexpr (std::is_same_v) \ { \ - return exact_integer(std::ROUND(static_cast(std::forward(x)))); \ + return exact_integer(CMATH(static_cast(x))); \ } \ else if constexpr (std::is_same_v) \ { \ - return std::forward(x); \ + return x; \ } \ else \ { \ - return complex(ROUND(x.real()), \ - ROUND(x.imag())); \ + return complex(NAME(x.real()), \ + NAME(x.imag())); \ } \ }; \ \ return apply_to(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 = [](T const& x) \ { \ if constexpr (std::is_same_v) \ { \ - auto const z = std::CMATH(static_cast>(std::forward(x))); \ + auto const z = CMATH(static_cast>(std::forward(x))); \ \ return complex(make(z.real()), \ make(z.imag())); \ } \ else \ { \ - return std::CMATH(static_cast(std::forward(x))); \ + return CMATH(static_cast(std::forward(x))); \ } \ }; \ \ return apply_to(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) \ @@ -984,9 +986,9 @@ inline namespace number return apply_to(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) \ @@ -998,9 +1000,9 @@ inline namespace number return apply_to(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 {