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

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

Save.

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