source: project/wiki/eggref/4/err5rs-arithmetic @ 13608

Last change on this file since 13608 was 13608, checked in by Kon Lovett, 11 years ago

Save.

File size: 12.4 KB
Line 
1[[tags: egg]]
2
3== err5rs-arithmetic
4
5[[toc:]]
6
7
8== Documentation
9
10ERR5RS arithmetic routines.
11
12See [[http://scheme-punks.cyber-rush.org/wiki/index.php?title=ERR5RS:SRFIs_and_Standard_Libraries|ERR5RS:SRFIs_and_Standard_Libraries]]
13
14
15=== Fixnum Arithmetic
16
17ERR5RS fixnum functions.
18
19See [[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_sec_11.2|Fixnums]]
20
21==== fixnum-width
22
23<procedure>(fixnum-width) => FIXNUM</procedure>
24
25==== least-fixnum
26
27<procedure>(least-fixnum) => FIXNUM</procedure>
28
29==== greatest-fixnum
30
31<procedure>(greatest-fixnum) => FIXNUM</procedure>
32
33==== fx=?
34
35<procedure>(fx=? FX ...) => BOOLEAN</procedure>
36
37==== fx<?
38
39<procedure>(fx<? FX ...) => BOOLEAN</procedure>
40
41==== fx>?
42
43<procedure>(fx>? FX ...) => BOOLEAN</procedure>
44
45==== fx<=?
46
47<procedure>(fx<=? FX ...) => BOOLEAN</procedure>
48
49==== fx>=?
50
51<procedure>(fx>=? FX ...) => BOOLEAN</procedure>
52
53==== fxcompare
54
55<procedure>(fxcompare FX1 FX2) => BOOLEAN</procedure>
56
57==== fxzero?
58
59<procedure>(fxzero? FX) => BOOLEAN</procedure>
60
61==== fxpositive?
62
63<procedure>(fxpositive? FX) => BOOLEAN</procedure>
64
65==== fxnegative?
66
67<procedure>(fxnegative? FX) => BOOLEAN</procedure>
68
69==== fxodd?
70
71<procedure>(fxodd? FX) => BOOLEAN</procedure>
72
73==== fxeven?
74
75<procedure>(fxeven? FX) => BOOLEAN</procedure>
76
77==== fxmax
78
79<procedure>(fxmax FX ...) => FIXNUM</procedure>
80
81==== fxmin
82
83<procedure>(fxmin FX ...) => FIXNUM</procedure>
84
85==== fxmax-and-min
86
87<procedure>(fxmax-and-min FX ...) => FIXNUM</procedure>
88
89==== fxmodulo
90
91<procedure>(fxmodulo FX-N FX-D) => FIXNUM</procedure>
92
93==== fxabs
94
95<procedure>(fxabs FX) => FIXNUM</procedure>
96
97==== fxpow2log2
98
99<procedure>(fxpow2log2 FX) => FIXNUM</procedure>
100
101==== fxdiv
102
103<procedure>(fxdiv FX-N FX-D) => FIXNUM</procedure>
104
105==== fxdiv-and-mod
106
107<procedure>(fxdiv-and-mod FX-N FX-D) => FIXNUM</procedure>
108
109==== fxdiv0
110
111<procedure>(fxdiv0 FX-N FX-D) => FIXNUM</procedure>
112
113==== fxmod0
114
115<procedure>(fxmod0 FX-N FX-D) => FIXNUM</procedure>
116
117==== fxdiv0-and-mod0
118
119<procedure>(fxdiv0-and-mod0 FX-N FX-D) => FIXNUM</procedure>
120
121==== fx*/carry
122
123<procedure>(fx*/carry FX1 FX2 FX3) => FIXNUM</procedure>
124
125==== fx+/carry
126
127<procedure>(fx+/carry FX1 FX2 FX3) => FIXNUM</procedure>
128
129==== fx-/carry
130
131<procedure>(fx-/carry FX1 FX2 FX3) => FIXNUM</procedure>
132
133==== fxadd1
134
135<procedure>(fxadd1 FX) => FIXNUM</procedure>
136
137==== fxsub1
138
139<procedure>(fxsub1 FX) => FIXNUM</procedure>
140
141==== fxquotient
142
143<procedure>(fxquotient FX-N FX-D) => FIXNUM</procedure>
144
145==== fxremainder
146
147<procedure>(fxremainder FX-N FX-D) => FIXNUM</procedure>
148
149==== fxarithmetic-shift
150
151<procedure>(fxarithmetic-shift FX DIRECTIONAL-AMOUNT) => FIXNUM</procedure>
152
153==== fxarithmetic-shift-left
154
155<procedure>(fxarithmetic-shift-left FX AMOUNT) => FIXNUM</procedure>
156
157==== fxarithmetic-shift-right
158
159<procedure>(fxarithmetic-shift-right FX AMOUNT) => FIXNUM</procedure>
160
161==== fx-
162
163<procedure>(fx- FX [FX2]) => FIXNUM</procedure>
164
165==== fxand
166
167<procedure>(fxand FX ...) => FIXNUM</procedure>
168
169==== fxior
170
171<procedure>(fxior FX ...) => FIXNUM</procedure>
172
173==== fxxor
174
175<procedure>(fxxor FX ...) => FIXNUM</procedure>
176
177==== fxif
178
179<procedure>(fxif MASK TRUE FALSE) => FIXNUM</procedure>
180
181==== fxbit-count
182
183<procedure>(fxbit-count FX) => FIXNUM</procedure>
184
185==== fxlength
186
187<procedure>(fxlength FX) => FIXNUM</procedure>
188
189==== fxfirst-bit-set
190
191<procedure>(fxfirst-bit-set FX) => FIXNUM</procedure>
192
193==== fxlast-bit-set
194
195<procedure>(fxlast-bit-set FX) => FIXNUM</procedure>
196
197==== fxbit-set?
198
199<procedure>(fxbit-set? FX INDEX) => BOOLEAN</procedure>
200
201==== fxcopy-bit
202
203<procedure>(fxcopy-bit FX INDEX BIT) => FIXNUM</procedure>
204
205==== fxbit-field
206
207<procedure>(fxbit-field FX START END) => FIXNUM</procedure>
208
209==== fxcopy-bit-field
210
211<procedure>(fxcopy-bit-field FX-TO START END FX-FROM) => FIXNUM</procedure>
212
213==== fxrotate-bit-field
214
215<procedure>(fxrotate-bit-field FX START END COUNT) => FIXNUM</procedure>
216
217==== fxreverse-bit-field
218
219<procedure>(fxreverse-bit-field FX START END) => FIXNUM</procedure>
220
221==== Extras
222
223===== fixnum->string
224
225<procedure>(fixnum->string FX [RADIX]) => STRING</procedure>
226
227===== fxif-not
228
229<procedure>(fxif-not MASK TRUE FALSE) => FIXNUM</procedure>
230
231===== fxnegate
232
233<procedure>(fxnegate FX) => FIXNUM</procedure>
234
235===== fxpow2log2
236
237<procedure>(fxpow2log2 FX) => FIXNUM</procedure>
238
239===== fx-#
240
241<procedure>(fx-# FX [FX1 ...]) => FIXNUM</procedure>
242
243===== fx+#
244
245<procedure>(fx+# FX [FX1 ...]) => FIXNUM</procedure>
246
247===== fx*#
248
249<procedure>(fx*# FX [FX1 ...]) => FIXNUM</procedure>
250
251===== fx/#
252
253<procedure>(fx/# FX [FX1 ...]) => FIXNUM</procedure>
254
255
256=== Flonum Arithmetic
257
258ERR5RS flonum functions.
259
260See [[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_sec_11.3|Flonums]]
261
262==== real->flonum
263
264<procedure>(real->flonum NUMBER) => FLONUM</procedure>
265
266==== fixnum->flonum
267
268<procedure>(fixnum->flonum FX) => FLONUM</procedure>
269
270==== fl=?
271
272<procedure>(fl=? FL ...) => BOOLEAN</procedure>
273
274==== fl<?
275
276<procedure>(fl<? FL ...) => BOOLEAN</procedure>
277
278==== fl>?
279
280<procedure>(fl>? FL ...) => BOOLEAN</procedure>
281
282==== fl<=?
283
284<procedure>(fl<=? FL ...) => BOOLEAN</procedure>
285
286==== fl>=?
287
288<procedure>(fl>=? FL ...) => BOOLEAN</procedure>
289
290==== flcompare
291
292<procedure>(flcompare FL1 FL2) => BOOLEAN</procedure>
293
294==== flinteger?
295
296<procedure>(flinteger? FL) => BOOLEAN</procedure>
297
298==== flzero?
299
300<procedure>(flzero? FL) => BOOLEAN</procedure>
301
302==== flpositive?
303
304<procedure>(flpositive? FL) => BOOLEAN</procedure>
305
306==== flnegative?
307
308<procedure>(flnegative? FL) => BOOLEAN</procedure>
309
310==== flodd?
311
312<procedure>(flodd? FL) => BOOLEAN</procedure>
313
314==== fleven?
315
316<procedure>(fleven? FL) => BOOLEAN</procedure>
317
318==== flfinite?
319
320<procedure>(flfinite? FL) => BOOLEAN</procedure>
321
322==== flinfinite?
323
324<procedure>(flinfinite? FL) => BOOLEAN</procedure>
325
326==== flnan?
327
328<procedure>(flnan? FL) => BOOLEAN</procedure>
329
330==== fl+
331
332<procedure>(fl+ FL ...) => FLONUM</procedure>
333
334==== fl*
335
336<procedure>(fl* FL ...) => FLONUM</procedure>
337
338==== fl-
339
340<procedure>(fl- FL ...) => FLONUM</procedure>
341
342==== fl/
343
344<procedure>(fl/ FL ...) => FLONUM</procedure>
345
346==== flmax
347
348<procedure>(flmax FL ...) => FLONUM</procedure>
349
350==== flmin
351
352<procedure>(flmin FL ...) => FLONUM</procedure>
353
354==== flmax-and-min
355
356<procedure>(flmax-and-min FL ...) => FLONUM</procedure>
357
358==== flabs
359
360<procedure>(flabs FL) => FLONUM</procedure>
361
362==== flfraction
363
364<procedure>(flfraction FL) => FLONUM</procedure>
365
366==== fltruncate
367
368<procedure>(fltruncate FL) => FLONUM</procedure>
369
370==== flfloor
371
372<procedure>(flfloor FL) => FLONUM</procedure>
373
374==== flceiling
375
376<procedure>(flceiling FL) => FLONUM</procedure>
377
378==== flround
379
380<procedure>(flround FL) => FLONUM</procedure>
381
382==== fldiv
383
384<procedure>(fldiv FL-N FL-D) => FLONUM</procedure>
385
386==== flmod
387
388<procedure>(flmod FL-N FL-D) => FLONUM</procedure>
389
390==== fldiv-and-mod
391
392<procedure>(fldiv-and-mod FL-N FL-D) => FLONUM</procedure>
393
394==== fldiv0
395
396<procedure>(fldiv0 FL-N FL-D) => FLONUM</procedure>
397
398==== flmod0
399
400<procedure>(flmod0 FL-N FL-D) => FLONUM</procedure>
401
402==== fldiv0-and-mod0
403
404<procedure>(fldiv0-and-mod0 FL-N FL-D) => FLONUM</procedure>
405
406==== flexp
407
408<procedure>(flexp FL) => FLONUM</procedure>
409
410==== fllog
411
412<procedure>(fllog FL [BASE]) => FLONUM</procedure>
413
414==== flsin
415
416<procedure>(flsin FL) => FLONUM</procedure>
417
418==== flcos
419
420<procedure>(flcos FL) => FLONUM</procedure>
421
422==== fltan
423
424<procedure>(fltan FL) => FLONUM</procedure>
425
426==== flasin
427
428<procedure>(flasin FL) => FLONUM</procedure>
429
430==== flacos
431
432<procedure>(flacos FL) => FLONUM</procedure>
433
434==== flatan
435
436<procedure>(flatan FL [FL2]) => FLONUM</procedure>
437
438==== flsqrt
439
440<procedure>(flsqrt FL) => FLONUM</procedure>
441
442==== flexpt
443
444<procedure>(flexpt FL EXP) => FLONUM</procedure>
445
446==== flnumerator
447
448<procedure>(flnumerator FL) => FLONUM</procedure>
449
450==== fldenominator
451
452<procedure>(fldenominator FL) => FLONUM</procedure>
453
454
455=== Bitwise Arithmetic
456
457ERR5RS bitwise functions.
458
459See [[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_sec_11.1|Exact bitwise arithmetic]]
460
461==== bitwise-if
462
463<procedure>(bitwise-if MASK TRUE FALSE) => INTEGER</procedure>
464
465==== bitwise-test?
466
467<procedure>(bitwise-test? VALUE1 VALUE2) => BOOLEAN</procedure>
468
469==== bitwise-bit-count
470
471<procedure>(bitwise-bit-count VALUE) => INTEGER</procedure>
472
473==== bitwise-length
474
475<procedure>(bitwise-length VALUE) => INTEGER</procedure>
476
477==== bitwise-first-bit-set
478
479<procedure>(bitwise-first-bit-set VALUE) => INTEGER</procedure>
480
481==== bitwise-last-bit-set
482
483<procedure>(bitwise-last-bit-set VALUE) => INTEGER</procedure>
484
485==== bitwise-bit-set?
486
487<procedure>(bitwise-bit-set? VALUE INDEX) => BOOLEAN</procedure>
488
489==== bitwise-copy-bit
490
491<procedure>(bitwise-copy-bit TO START BIT) => INTEGER</procedure>
492
493==== bitwise-bit-field
494
495<procedure>(bitwise-bit-field VALUE START END) => INTEGER</procedure>
496
497==== bitwise-copy-bit-field
498
499<procedure>(bitwise-copy-bit-field TO START END FROM) => INTEGER</procedure>
500
501==== bitwise-rotate-bit-field
502
503<procedure>(bitwise-rotate-bit-field VALUE START END COUNT) => INTEGER</procedure>
504
505==== bitwise-reverse
506
507<procedure>(bitwise-reverse VALUE COUNT) => INTEGER</procedure>
508
509==== bitwise-reverse-bit-field
510
511<procedure>(bitwise-reverse-bit-field VALUE START END) => INTEGER</procedure>
512
513==== bitwise-list->integer
514
515<procedure>(bitwise-list->integer LIST) => INTEGER</procedure>
516
517==== bitwise-integer->list
518
519<procedure>(bitwise-integer->list VALUE [LENGTH]) => LIST</procedure>
520
521==== bitwise-arithmetic-shift
522
523<procedure>(bitwise-arithmetic-shift VALUE DIRECTIONAL-COUNT) => INTEGER</procedure>
524
525==== bitwise-arithmetic-shift-left
526
527<procedure>(bitwise-arithmetic-shift-left VALUE COUNT) => INTEGER</procedure>
528
529==== bitwise-arithmetic-shift-right
530
531<procedure>(bitwise-arithmetic-shift-right VALUE COUNT) => INTEGER</procedure>
532
533==== Extras
534
535===== bitwise-if-not
536
537<procedure>(bitwise-if-not MASK TRUE FALSE) => INTEGER</procedure>
538
539Merge under not mask.
540
541===== pow2log2
542
543<procedure>(pow2log2 VALUE) => INTEGER</procedure>
544
545Returns {{(* 2 (log2 VALUE))}}, but more efficient.
546
547===== boolean->bit
548
549<procedure>(boolean->bit OBJECT) => INTEGER</procedure>
550
551Returns {{0}} for {{#f}} or {{0}} and {{1}} otherwise.
552
553==== Unchecked variants
554
555These procedures have the same signature as the similarly named ones but
556perform no argument checking.
557
558===== *bitwise-if
559===== *bitwise-if-not
560===== *bitwise-test?
561===== *bitwise-bit-count
562===== *bitwise-length
563===== *bitwise-first-bit-set
564===== *bitwise-last-bit-set
565===== *bitwise-bit-set?
566===== *bitwise-copy-bit
567===== *bitwise-bit-field
568===== *bitwise-copy-bit-field
569===== *bitwise-rotate-bit-field
570===== *bitwise-reverse
571===== *bitwise-reverse-bit-field
572===== *bitwise-reverse-bit-field
573===== *bitwise-list->integer
574===== *bitwise-integer->list
575===== *bitwise-arithmetic-shift
576===== *bitwise-arithmetic-shift-left
577===== *bitwise-arithmetic-shift-right
578===== *pow2log2
579
580
581== Usage
582
583
584=== Fixnum Arithmetic
585
586<enscript language=scheme>
587(require-library err5rs-arithmetic-fixnum)
588...
589(import err5rs-arithmetic)
590</enscript>
591
592or
593
594<enscript language=scheme>
595(require-extension err5rs-arithmetic-fixnum)
596</enscript>
597
598
599=== Flonum Arithmetic
600
601<enscript language=scheme>
602(require-library err5rs-arithmetic-fixnum)
603...
604(import err5rs-arithmetic)
605</enscript>
606
607or
608
609<enscript language=scheme>
610(require-extension err5rs-arithmetic-fixnum)
611</enscript>
612
613
614=== Bitwise Arithmetic
615
616<enscript language=scheme>
617(require-library err5rs-arithmetic-fixnum)
618...
619(import err5rs-arithmetic)
620</enscript>
621
622or
623
624<enscript language=scheme>
625(require-extension err5rs-arithmetic-fixnum)
626</enscript>
627
628
629== Examples
630
631
632== Notes
633
634
635== Requirements
636
637
638== Bugs and Limitations
639
640* No ERR5RS full-numeric-tower arithmetic routines.
641
642
643== Author
644
645[[kon lovett]]
646
647
648== Version history
649
650; 1.0.0 : Chicken 4 release.
651
652
653== License
654
655Copyright (C) 2009 Kon Lovett.  All rights reserved.
656
657Permission is hereby granted, free of charge, to any person obtaining a
658copy of this software and associated documentation files (the Software),
659to deal in the Software without restriction, including without limitation
660the rights to use, copy, modify, merge, publish, distribute, sublicense,
661and/or sell copies of the Software, and to permit persons to whom the
662Software is furnished to do so, subject to the following conditions:
663
664The above copyright notice and this permission notice shall be included
665in all copies or substantial portions of the Software.
666
667THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
668IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
669FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
670THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
671OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
672ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
673OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.