Skip to content

Commit

Permalink
Add procedure log-gamma
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 15, 2024
1 parent 71e2bbe commit 7fe4bf0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 15 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.294.so` and executable `meevax`.
| `all` | Build shared-library `libmeevax.0.5.295.so` and executable `meevax`.
| `install` | Copy files into `/usr/local` directly.
| `package` | Generate debian package `meevax_0.5.294_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.294_amd64.deb`.
| `package` | Generate debian package `meevax_0.5.295_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.295_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.294
0.5.295
11 changes: 9 additions & 2 deletions basis/srfi-144.ss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
euler
gamma
load-exponent
log-gamma
next-after
phi
pi
Expand Down Expand Up @@ -121,8 +122,8 @@

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 @@ -382,5 +383,11 @@
(values (car rq)
(cdr rq))))

(define flgamma gamma)

(define (flloggamma x)
(values (log-gamma x)
(if (positive? (gamma x)) 1.0 -1.0)))

)
)
2 changes: 2 additions & 0 deletions include/meevax/kernel/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ inline namespace number

auto gamma(object const&) -> object;

auto log_gamma(object const&) -> object;

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

auto next_after(object const&, object const&) -> object;
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ namespace meevax::inline kernel
return gamma(car(xs));
});

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

library.define<procedure>("next-after", [](let const& xs)
{
return next_after(car(xs), cadr(xs));
Expand Down
3 changes: 2 additions & 1 deletion src/kernel/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,8 @@ inline namespace number
return apply_to<real_number>(f, x); \
}

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

#define DEFINE_REAL2(NAME, CMATH) \
auto NAME(object const& x, object const& y) -> object \
Expand Down
26 changes: 17 additions & 9 deletions test/srfi-144.ss
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,23 @@
(check (flremainder 3.14 -0.5) (=> =) 0.14)
(check (flremainder -3.14 -0.5) (=> =) -0.14)

(call-with-values (lambda () (flremquo 5.0 2.0)) (lambda (r q) (check q => 2) (check r => 1.0)))
(call-with-values (lambda () (flremquo 6.0 4.0)) (lambda (r q) (check q => 2) (check r => -2.0)))
(call-with-values (lambda () (flremquo 6.3 3.0)) (lambda (r q) (check q => 2) (check r (=> =) 0.3)))
(call-with-values (lambda () (flremquo 6.3 -3.0)) (lambda (r q) (check q => -2) (check r (=> =) 0.3)))
(call-with-values (lambda () (flremquo -6.3 3.0)) (lambda (r q) (check q => -2) (check r (=> =) -0.3)))
(call-with-values (lambda () (flremquo -6.3 -3.0)) (lambda (r q) (check q => 2) (check r (=> =) -0.3)))
(call-with-values (lambda () (flremquo 6.3 3.15)) (lambda (r q) (check q => 2) (check r => 0.0)))
(call-with-values (lambda () (flremquo 6.0 2.0)) (lambda (r q) (check q => 3) (check r => 0.0)))
(call-with-values (lambda () (flremquo 5.0 2.0 )) (lambda (r q) (check q => 2) (check r => 1.0)))
(call-with-values (lambda () (flremquo 6.0 4.0 )) (lambda (r q) (check q => 2) (check r => -2.0)))
(call-with-values (lambda () (flremquo 6.3 3.0 )) (lambda (r q) (check q => 2) (check r (=> =) 0.3)))
(call-with-values (lambda () (flremquo 6.3 -3.0 )) (lambda (r q) (check q => -2) (check r (=> =) 0.3)))
(call-with-values (lambda () (flremquo -6.3 3.0 )) (lambda (r q) (check q => -2) (check r (=> =) -0.3)))
(call-with-values (lambda () (flremquo -6.3 -3.0 )) (lambda (r q) (check q => 2) (check r (=> =) -0.3)))
(call-with-values (lambda () (flremquo 6.3 3.15)) (lambda (r q) (check q => 2) (check r => 0.0)))
(call-with-values (lambda () (flremquo 6.0 2.0 )) (lambda (r q) (check q => 3) (check r => 0.0)))

(check (flgamma 0.5) => fl-gamma-1/2)
(check (flgamma 2/3) => fl-gamma-2/3)

(call-with-values (lambda () (flloggamma 0.0)) (lambda (value sign) (check value => +inf.0) (check sign => 1.0)))
(call-with-values (lambda () (flloggamma 0.5)) (lambda (value sign) (check value => (log fl-gamma-1/2)) (check sign => 1.0)))
(call-with-values (lambda () (flloggamma 1.0)) (lambda (value sign) (check value => 0.0) (check sign => 1.0)))
(call-with-values (lambda () (flloggamma +inf.0)) (lambda (value sign) (check value => +inf.0) (check sign => 1.0)))

(check-report)

(exit (check-passed? 222))
(exit (check-passed? 232))

0 comments on commit 7fe4bf0

Please sign in to comment.