Skip to content

Commit

Permalink
Add procedure erf and erfc
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 21, 2024
1 parent fe95ba7 commit aa926e2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 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.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`.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.298
0.5.299
11 changes: 6 additions & 5 deletions basis/srfi-144.ss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
cyl_bessel_j
cyl_neumann
e
erf
erfc
euler
gamma
load-exponent
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -395,5 +395,6 @@

(define flsecond-bessel cyl_neumann)

)
)
(define flerf erf)

(define flerfc erfc)))
4 changes: 4 additions & 0 deletions include/meevax/kernel/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ namespace meevax::inline kernel
return cyl_neumann(car(xs), cadr(xs));
});

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

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

library.define<double>("e", std::numbers::e);

library.define<double>("pi", std::numbers::pi);
Expand Down
2 changes: 2 additions & 0 deletions src/kernel/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ inline namespace number
return apply_to<real_number>(f, x); \
}

DEFINE_REAL1(erf, std::erf)
DEFINE_REAL1(erfc, std::erfc)
DEFINE_REAL1(gamma, std::tgamma)
DEFINE_REAL1(log_gamma, std::lgamma)

Expand Down
21 changes: 12 additions & 9 deletions test/srfi-144.ss
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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))

0 comments on commit aa926e2

Please sign in to comment.