Generic Flonums
(require generic-flonum) | package: generic-flonum |
This library provides an alternate interface to MPFR (compared to math/bigfloat), emphasizing the emulation of floating-point formats such as binary128, binary16, bfloat16, etc.
1 Introduction
properly emulate subnormal arithmetic
allow the exponent range to be changed
At half-precision, (exp -10) and (exp 20) evaluate to 4.5419e-5 and +inf.0, respectively. On the other hand, evaluating (bfexp (bf -10)) and (bfexp (bf -10)) with (bf-precision 11) returns (bf "4.5389e-5") and (bf "#e4.8523e8"). While the latter results are certainly more accurate, they do not reflect proper behavior in half-precision. The standard bigfloat library does not subnormalize the first result (no subnormal arithmetic), nor does it recognize the overflow in the second result (fixed exponent range).
This library fixes the issues mentioned above by automatically emulating subnormal arithmetic when necessary and providing a way to change the exponent range. In addition, the interface is quite similar to math/bigfloat, so it will feel familiar to anyone who has used the standard bigfloat library before. There are also a few extra operations from the C math library such as gflfma, gflmod, and gflremainder that the bigfloat library does not support.
See math/bigfloat for more information on bigfloats.
2 Type
A generic flonum is a wrapper that stores a bigfloat and the significand and exponent size when it was initialized.
procedure
(gfl-init-exponent x) → gfl?
x : gfl?
procedure
(gfl-init-bits x) → gfl?
x : gfl?
3 Conversions
procedure
(bigfloat->gfl v) → gfl?
v : bigfloat?
procedure
(gfl->bigfloat x) → bigfloat?
x : gfl?
procedure
(ordinal->gfl o) → gfl?
o : exact-integer?
procedure
(gfl->ordinal x) → exact-integer?
x : gfl?
procedure
(string->gfl s) → gfl?
s : string?
procedure
(gfl->string x) → string?
x : gfl?
4 Parameters
The standard bigfloat library defines (bf-precision) and (bf-rounding-mode) to control significand size and the rounding of results. The following parameters are similar and can be used at the same time as their bigfloat counterparts, although this behavior may change in the future.
parameter
(gfl-exponent es) → void? es : exact-positive-integer?
= 11
parameter
(gfl-bits nb) → void? nb : exact-positive-integer?
= 64
parameter
(gfl-rounding-mode) → (symbols 'nearest 'zero 'up 'down 'away)
(gfl-rounding-mode rm) → void? rm : (symbols 'nearest 'zero 'up 'down 'away)
= 'nearest
parameter
(gfl-verbose?) → boolean?
(gfl-verbose? b) → void? b : boolean?
= #t
5 Constants
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
6 Predicates
procedure
x : gfl?
procedure
(gflpositive? x) → boolean?
x : gfl?
procedure
(gflnegative? x) → boolean?
x : gfl?
procedure
(gflinfinite? x) → boolean?
x : gfl?
procedure
x : gfl?
procedure
(gflsubnormal? x) → boolean?
x : gfl?
7 Mathematical Operations
procedure
x : gfl?
procedure
x : gfl? y : gfl?
procedure
x : gfl?
procedure
x : gfl? y : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
When giving more than two arguments, gfl+ and gfl- compute the answer without any intermediate rounding.
Unlike bfmin and bfmax, these functions are C99 compliant and will only return +nan.gfl if all arguments are +nan.gfl.
procedure
x : gfl? n : exact-nonnegative-integer?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl? y : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
(gflsin+cos x) →
gfl? gfl? x : gfl?
procedure
(gflsinh+cosh x) →
gfl? gfl? x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
(gfldigamma x) → gfl?
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
n : exact-integer? x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
n : exact-integer? x : gfl?
8 Rounding
procedure
(gflceiling x) → gfl?
x : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
(gfltruncate x) → gfl?
x : gfl?
9 Miscellaneous
procedure
(gflcopysign x y) → gfl?
x : gfl? y : gfl?
procedure
(gfls-between x y) → gfl?
x : gfl? y : gfl?
procedure
x : gfl?
procedure
x : gfl?
procedure
x : gfl? n : exact-integer?