Skip to content

Commit

Permalink
Add procedures binary64-normalized? and binary64-denormalized?
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 4cd524e commit b02e966
Show file tree
Hide file tree
Showing 5 changed files with 120 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.286.so` and executable `meevax`.
| `all` | Build shared-library `libmeevax.0.5.287.so` and executable `meevax`.
| `install` | Copy files into `/usr/local` directly.
| `package` | Generate debian package `meevax_0.5.286_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.286_amd64.deb`.
| `package` | Generate debian package `meevax_0.5.287_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.287_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.286
0.5.287
73 changes: 64 additions & 9 deletions basis/srfi-144.ss
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(define-library (srfi 144)
(import (only (meevax inexact)
FP_FAST_FMA
FP_ILOGB0
FP_ILOGBNAN
binary64-denormalized?
binary64-epsilon
binary64-exponent
binary64-fractional-part
Expand All @@ -12,7 +11,9 @@
binary64-max
binary64-min
binary64-normalized-fraction
binary64-normalized?
binary64-sign-bit
binary64?
copy-sign
e
euler
Expand All @@ -25,15 +26,31 @@
(only (scheme base)
*
/
<
<=
=
>
>=
and
define
even?
expt
if
inexact
integer?
negative?
odd?
or
positive?
values
zero?
)
(only (scheme inexact)
cos
finite?
infinite?
log
nan?
sin
sqrt
)
Expand All @@ -54,11 +71,10 @@
flinteger-fraction flexponent flinteger-exponent
flnormalized-fraction-exponent flsign-bit

; flonum? fl=? fl<? fl>? fl<=? fl>=?
; flunordered? flinteger? flzero? flpositive? flnegative?
; flodd? fleven? flfinite? flinfinite? flnan?
; flnormalized? fldenormalized?
;
flonum? fl=? fl<? fl>? fl<=? fl>=? flunordered? flinteger? flzero?
flpositive? flnegative? flodd? fleven? flfinite? flinfinite? flnan?
flnormalized? fldenormalized?

; flmax flmin fl+ fl* fl+* fl- fl/ flabs flabsdiff
; flposdiff flsgn flnumerator fldenominator
; flfloor flceiling flround fltruncate
Expand Down Expand Up @@ -161,9 +177,9 @@

(define fl-fast-fl+* FP_FAST_FMA)

(define fl-integer-exponent-zero FP_ILOGB0)
(define fl-integer-exponent-zero (binary64-integer-log-binary 0.0))

(define fl-integer-exponent-nan FP_ILOGBNAN)
(define fl-integer-exponent-nan (binary64-integer-log-binary +nan.0))

(define flonum inexact)

Expand All @@ -188,5 +204,44 @@
(define (flsign-bit x)
(if (binary64-sign-bit x) 1 0))

(define flonum? binary64?)

(define fl=? =)

(define fl<? <)

(define fl>? >)

(define fl<=? <=)

(define fl>=? >=)

(define (flunordered? x y)
(or (nan? x)
(nan? y)))

(define (flinteger? x)
(and (binary64? x)
(integer? x)))

(define flzero? zero?)

(define flpositive? positive?)

(define flnegative? negative?)

(define flodd? odd?)

(define fleven? even?)

(define flfinite? finite?)

(define flinfinite? infinite?)

(define flnan? nan?)

(define flnormalized? binary64-normalized?)

(define fldenormalized? binary64-denormalized?)
)
)
14 changes: 10 additions & 4 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ namespace meevax::inline kernel
return make(std::signbit(car(xs).as<double>()));
});

library.define<procedure>("binary64-normalized?", [](let const& xs)
{
return std::fpclassify(car(xs).as<double>()) == FP_NORMAL;
});

library.define<procedure>("binary64-denormalized?", [](let const& xs)
{
return std::fpclassify(car(xs).as<double>()) == FP_SUBNORMAL;
});

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

library.define<double>("pi", std::numbers::pi);
Expand All @@ -625,10 +635,6 @@ namespace meevax::inline kernel

library.define<double>("binary64-epsilon", std::numeric_limits<double>::epsilon());

library.define<exact_integer>("FP_ILOGB0", FP_ILOGB0);

library.define<exact_integer>("FP_ILOGBNAN", FP_ILOGBNAN);

#ifdef FP_FAST_FMA
library.define<bool>("FP_FAST_FMA", true);
#else
Expand Down
44 changes: 43 additions & 1 deletion test/srfi-144.ss
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,48 @@

(check (flsign-bit -3.14) => 1)

(check (flonum? 1.0) => #t)

(check (flonum? 1.0f0) => #f)

(check (procedure? fl=?) => #t)

(check (procedure? fl<?) => #t)

(check (procedure? fl>?) => #t)

(check (procedure? fl<=?) => #t)

(check (procedure? fl>=?) => #t)

(check (flunordered? 1.0 2.0) => #f)

(check (flunordered? 1.0 +nan.0) => #t)

(check (flinteger? 3.14) => #f)

(check (flinteger? 1.0) => #t)

(check (procedure? flzero?) => #t)

(check (procedure? flpositive?) => #t)

(check (procedure? flnegative?) => #t)

(check (procedure? flodd?) => #t)

(check (procedure? fleven?) => #t)

(check (procedure? flfinite?) => #t)

(check (procedure? flinfinite?) => #t)

(check (procedure? flnan?) => #t)

(check (flnormalized? 1.0) => #t)

(check (fldenormalized? (/ fl-least 2)) => #t)

(check-report)

(exit (check-passed? 69))
(exit (check-passed? 90))

0 comments on commit b02e966

Please sign in to comment.