The Lambda Lab
/
projects
/
scheme.forth.jl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implemented fix:gcd.
[scheme.forth.jl.git]
/
src
/
scheme-primitives.4th
diff --git
a/src/scheme-primitives.4th
b/src/scheme-primitives.4th
index
8dad18e
..
7e123f7
100644
(file)
--- a/
src/scheme-primitives.4th
+++ b/
src/scheme-primitives.4th
@@
-151,7
+151,7
@@
\ }}}
\ }}}
-\ ====
Primitivle Arithmetic
==== {{{
+\ ====
Numeric types
==== {{{
\ --- Fixnums ---
\ --- Fixnums ---
@@
-219,11
+219,31
@@
swap negate swap
; 1 make-fa-primitive fix:neg
swap negate swap
; 1 make-fa-primitive fix:neg
+:noname ( fixnum -- -fixnum )
+ swap abs swap
+; 1 make-fa-primitive fix:abs
+
+: sort-pair
+ 2dup > if
+ swap
+ then
+;
+
( Find the GCD of n1 and n2 where n2 < n1. )
: gcd ( n1 n2 -- m )
( Find the GCD of n1 and n2 where n2 < n1. )
: gcd ( n1 n2 -- m )
-
+ sort-pair
+ over 0= if
+ swap drop
+ else
+ over mod
+ recurse
+ then
;
;
+:noname ( fixnum fixnum -- fixnum' )
+ drop swap drop gcd fixnum-type
+; 2 make-fa-primitive fix:gcd
+
\ --- Flonums ---
:noname ( flonum flonum -- bool )
\ --- Flonums ---
:noname ( flonum flonum -- bool )
@@
-279,6
+299,10
@@
; 1 make-fa-primitive flo:finite?
; 1 make-fa-primitive flo:finite?
+:noname ( flonum -- flonum )
+ swap -1.0 f* swap
+; 1 make-fa-primitive flo:neg
+
:noname ( flonum -- flonum )
swap fabs swap
; 1 make-fa-primitive flo:abs
:noname ( flonum -- flonum )
swap fabs swap
; 1 make-fa-primitive flo:abs
@@
-359,6
+383,13
@@
drop swap drop f/ fatan flonum-type
; 2 make-fa-primitive flo:atan2
drop swap drop f/ fatan flonum-type
; 2 make-fa-primitive flo:atan2
+
+\ --- Conversion ---
+
+:noname ( fixnum -- flonum )
+ drop i->f flonum-type
+; 1 make-fa-primitive fixnum->flonum
+
\ }}}
\ ==== Pairs and Lists ==== {{{
\ }}}
\ ==== Pairs and Lists ==== {{{