-
Notifications
You must be signed in to change notification settings - Fork 1
/
srfi-144.ss
325 lines (192 loc) · 8.14 KB
/
srfi-144.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
(define-library (srfi 144)
(import (only (meevax binary64)
binary64-denormalized? binary64-epsilon binary64-exponent
binary64-fractional-part binary64-fused-multiply-add
binary64-greatest binary64-integer-log-binary
binary64-integral-part binary64-least binary64-log-binary
binary64-max binary64-min binary64-normalized-fraction
binary64-normalized? binary64-remquo binary64-sign-bit binary64?)
(only (meevax inexact)
acosh asinh atanh copysign cosh cyl_bessel_j cyl_neumann e erf erfc
euler expm1 fabs ldexp lgamma log1p nextafter phi pi sinh tanh
tgamma)
(only (scheme base)
* + - / < <= = > >= and car cdr ceiling cond-expand define
denominator even? expt floor if inexact integer? lambda let
negative? numerator odd? or positive? quotient remainder round
square truncate values zero?)
(only (scheme inexact)
acos asin atan cos exp finite? infinite? log nan? sin sqrt tan))
(export fl-e fl-1/e fl-e-2 fl-e-pi/4 fl-log2-e fl-log10-e fl-log-2 fl-1/log-2
fl-log-3 fl-log-pi fl-log-10 fl-1/log-10 fl-pi fl-1/pi fl-2pi fl-pi/2
fl-pi/4 fl-pi-squared fl-degree fl-2/pi fl-2/sqrt-pi fl-sqrt-2
fl-sqrt-3 fl-sqrt-5 fl-sqrt-10 fl-1/sqrt-2 fl-cbrt-2 fl-cbrt-3
fl-4thrt-2 fl-phi fl-log-phi fl-1/log-phi fl-euler fl-e-euler
fl-sin-1 fl-cos-1 fl-gamma-1/2 fl-gamma-1/3 fl-gamma-2/3
fl-greatest fl-least fl-epsilon fl-fast-fl+* fl-integer-exponent-zero
fl-integer-exponent-nan
flonum fladjacent flcopysign make-flonum
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?
flmax flmin fl+ fl* fl+* fl- fl/ flabs flabsdiff flposdiff flsgn
flnumerator fldenominator flfloor flceiling flround fltruncate
flexp flexp2 flexp-1 flsquare flsqrt flcbrt flhypot flexpt fllog
fllog1+ fllog2 fllog10 make-fllog-base
flsin flcos fltan flasin flacos flatan flsinh flcosh fltanh flasinh
flacosh flatanh
flquotient flremainder flremquo
flgamma flloggamma flfirst-bessel flsecond-bessel flerf flerfc)
(begin (define fl-e e)
(define fl-1/e (/ 1 e))
(define fl-e-2 7.38905609893065) ; (define fl-e-2 (expt e 2)) yields 1 ULP error
(define fl-e-pi/4 (expt e (/ pi 4)))
(define fl-log2-e (log e 2))
(define fl-log10-e 0.4342944819032518) ; (define fl-log10-e (log e 10)) yields 1 ULP error
(define fl-log-2 (log 2))
(define fl-1/log-2 (/ 1 (log 2)))
(define fl-log-3 (log 3))
(define fl-log-pi (log pi))
(define fl-log-10 (log 10))
(define fl-1/log-10 0.4342944819032518) ; (define fl-1/log-10 (/ 1 (log 10))) yields 1 ULP error
(define fl-pi pi)
(define fl-1/pi (/ 1 pi))
(define fl-2pi (* 2 pi))
(define fl-pi/2 (/ pi 2))
(define fl-pi/4 (/ pi 4))
(define fl-pi-squared (expt pi 2))
(define fl-degree (/ pi 180))
(define fl-2/pi (/ 2 pi))
(define fl-2/sqrt-pi (/ 2 (sqrt pi)))
(define fl-sqrt-2 (sqrt 2))
(define fl-sqrt-3 (sqrt 3))
(define fl-sqrt-5 (sqrt 5))
(define fl-sqrt-10 (sqrt 10))
(define fl-1/sqrt-2 (/ 1 (sqrt 2)))
(define fl-cbrt-2 (expt 2 (/ 1 3)))
(define fl-cbrt-3 (expt 3 (/ 1 3)))
(define fl-4thrt-2 (expt 2 (/ 1 4)))
(define fl-phi phi)
(define fl-log-phi (log phi))
(define fl-1/log-phi 2.07808692123502753) ; (define fl-1/log-phi (/ 1 fl-log-phi)) yields 1 ULP error
(define fl-euler euler)
(define fl-e-euler (expt e euler))
(define fl-sin-1 (sin 1))
(define fl-cos-1 (cos 1))
(define fl-gamma-1/2 (tgamma (/ 1 2)))
(define fl-gamma-1/3 2.67893853470774763) ; (define fl-gamma-1/3 (tgamma (/ 1 3))) yields 1 ULP error
(define fl-gamma-2/3 (tgamma (/ 2 3)))
(define fl-greatest binary64-greatest)
(define fl-least binary64-least)
(define fl-epsilon binary64-epsilon)
(define fl-fast-fl+*
(cond-expand
(FP_FAST_FMA #f)
(else #f)))
(define fl-integer-exponent-zero (binary64-integer-log-binary 0.0))
(define fl-integer-exponent-nan (binary64-integer-log-binary +nan.0))
(define flonum inexact)
(define fladjacent nextafter)
(define flcopysign copysign)
(define make-flonum ldexp)
(define (flinteger-fraction x)
(values (binary64-integral-part x)
(binary64-fractional-part x)))
(define flexponent binary64-log-binary)
(define flinteger-exponent binary64-integer-log-binary)
(define (flnormalized-fraction-exponent x)
(values (binary64-normalized-fraction x)
(binary64-exponent x)))
(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?)
(define flmax binary64-max)
(define flmin binary64-min)
(define fl+ +)
(define fl* *)
(define fl+* binary64-fused-multiply-add)
(define fl- -)
(define fl/ /)
(define flabs fabs)
(define (flabsdiff x y)
(flabs (- x y)))
(define (flposdiff x y)
(flmax (fl- x y) 0.0))
(define (flsgn x)
(flcopysign 1.0 x))
(define flnumerator numerator)
(define fldenominator denominator)
(define flfloor floor)
(define flceiling ceiling)
(define flround round)
(define fltruncate truncate)
(define flexp exp)
(define (flexp2 x)
(expt 2 x))
(define flexp-1 expm1)
(define flsquare square)
(define flsqrt sqrt)
(define (flcbrt x)
(expt x (/ 1 3)))
(define (flhypot x y)
(sqrt (+ (square x)
(square y))))
(define flexpt expt)
(define fllog log)
(define fllog1+ log1p)
(define (fllog2 x)
(log x 2))
(define (fllog10 x)
(log x 10))
(define (make-fllog-base b)
(lambda (x)
(log x b)))
(define flsin sin)
(define flcos cos)
(define fltan tan)
(define flasin asin)
(define flacos acos)
(define flatan atan)
(define flsinh sinh)
(define flcosh cosh)
(define fltanh tanh)
(define flasinh asinh)
(define flacosh acosh)
(define flatanh atanh)
(define flquotient quotient)
(define flremainder remainder)
(define (flremquo x y)
(let ((rq (binary64-remquo x y)))
(values (car rq)
(cdr rq))))
(define flgamma tgamma)
(define (flloggamma x)
(values (lgamma x)
(if (positive? (tgamma x)) 1.0 -1.0)))
(define flfirst-bessel cyl_bessel_j)
(define flsecond-bessel cyl_neumann)
(define flerf erf)
(define flerfc erfc)))