From aa926e2e177f668b13ad6f2e49c7f7e18cdb2da8 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 Dec 2024 22:15:40 +0900 Subject: [PATCH] Add procedure `erf` and `erfc` Signed-off-by: yamacir-kit --- README.md | 4 ++-- VERSION | 2 +- basis/srfi-144.ss | 11 ++++++----- include/meevax/kernel/number.hpp | 4 ++++ src/kernel/boot.cpp | 10 ++++++++++ src/kernel/number.cpp | 2 ++ test/srfi-144.ss | 21 ++++++++++++--------- 7 files changed, 37 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e591b4cee..1268249fb 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.298.so` and executable `meevax`. +| `all` | Build shared-library `libmeevax.0.5.299.so` and executable `meevax`. | `install` | Copy files into `/usr/local` directly. -| `package` | Generate debian package `meevax_0.5.298_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.298_amd64.deb`. +| `package` | Generate debian package `meevax_0.5.299_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.299_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 a5fbe31d1..bbaa11a78 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.298 +0.5.299 diff --git a/basis/srfi-144.ss b/basis/srfi-144.ss index f828b53a6..7bee5f148 100644 --- a/basis/srfi-144.ss +++ b/basis/srfi-144.ss @@ -31,6 +31,8 @@ cyl_bessel_j cyl_neumann e + erf + erfc euler gamma load-exponent @@ -124,9 +126,7 @@ flquotient flremainder flremquo - flgamma flloggamma flfirst-bessel flsecond-bessel - ; flerf flerfc - ) + flgamma flloggamma flfirst-bessel flsecond-bessel flerf flerfc) (begin (define fl-e e) @@ -395,5 +395,6 @@ (define flsecond-bessel cyl_neumann) - ) - ) + (define flerf erf) + + (define flerfc erfc))) diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 63cc2dd72..5a69452f8 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -385,6 +385,10 @@ inline namespace number auto gamma(object const&) -> object; + auto erf(object const&) -> object; + + auto erfc(object const&) -> object; + auto log_gamma(object const&) -> object; auto copy_sign(object const&, object const&) -> object; diff --git a/src/kernel/boot.cpp b/src/kernel/boot.cpp index 3e1f60b4c..14d15af82 100644 --- a/src/kernel/boot.cpp +++ b/src/kernel/boot.cpp @@ -575,6 +575,16 @@ namespace meevax::inline kernel return cyl_neumann(car(xs), cadr(xs)); }); + library.define("erf", [](let const& xs) + { + return erf(car(xs)); + }); + + library.define("erfc", [](let const& xs) + { + return erfc(car(xs)); + }); + library.define("e", std::numbers::e); library.define("pi", std::numbers::pi); diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index f0fb8f194..87c597a89 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -994,6 +994,8 @@ inline namespace number return apply_to(f, x); \ } + DEFINE_REAL1(erf, std::erf) + DEFINE_REAL1(erfc, std::erfc) DEFINE_REAL1(gamma, std::tgamma) DEFINE_REAL1(log_gamma, std::lgamma) diff --git a/test/srfi-144.ss b/test/srfi-144.ss index 166da20ee..7523acfcd 100644 --- a/test/srfi-144.ss +++ b/test/srfi-144.ss @@ -1,11 +1,4 @@ -(import (only (meevax inexact) - acosh - asinh - atanh - cosh - sinh - tanh - ) +(import (only (meevax inexact) acosh asinh atanh cosh sinh tanh) (scheme base) (scheme inexact) (scheme process-context) @@ -380,6 +373,16 @@ (check (cond-expand (__cpp_lib_math_special_functions (flsecond-bessel 1.0 (* 1/3 fl-pi))) (else -0.74108949656080647)) => -0.74108949656080647) (check (cond-expand (__cpp_lib_math_special_functions (flsecond-bessel 1.0 (* 2/3 fl-pi))) (else -0.05472495339562021)) => -0.05472495339562021) +(check (flerf -inf.0) => -1.0) +(check (flerf 0.0) => 0.0) +(check (flerf 1.0) => 0.8427007929497149) +(check (flerf +inf.0) => 1.0) + +(check (flerfc -inf.0) => 2.0) +(check (flerfc 0.0) => 1.0) +(check (flerfc 1.0) => 0.15729920705028513) +(check (flerfc +inf.0) => 0.0) + (check-report) -(exit (check-passed? 250)) +(exit (check-passed? 258))