]> gitweb.factorcode.org Git - factor.git/commitdiff
fix some overflow issues
authorSlava Pestov <slava@factorcode.org>
Fri, 27 Aug 2004 02:21:17 +0000 (02:21 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 27 Aug 2004 02:21:17 +0000 (02:21 +0000)
88 files changed:
contrib/mandel.factor
library/cross-compiler.factor
library/errors.factor
library/format.factor
library/hashtables.factor
library/httpd/httpd.factor
library/httpd/url-encoding.factor
library/image.factor
library/interpreter.factor
library/jedit/jedit-local.factor
library/jedit/jedit.factor
library/lists.factor
library/math/arc-trig-hyp.factor
library/math/arithmetic.factor
library/math/list-math.factor
library/math/math-combinators.factor
library/math/math.factor
library/math/namespace-math.factor
library/math/pow.factor
library/math/quadratic.factor
library/math/simpson.factor
library/math/trig-hyp.factor
library/platform/jvm/arithmetic.factor
library/platform/jvm/cross-compiler.factor
library/platform/jvm/kernel.factor
library/platform/jvm/math-types.factor
library/platform/jvm/prettyprint.factor
library/platform/jvm/real-math.factor
library/platform/jvm/regexp.factor
library/platform/native/boot-stage2.factor
library/platform/native/debugger.factor
library/platform/native/kernel.factor
library/platform/native/math.factor [new file with mode: 0644]
library/platform/native/namespaces.factor
library/platform/native/parse-numbers.factor
library/platform/native/parse-stream.factor
library/platform/native/parse-syntax.factor
library/platform/native/parser.factor
library/platform/native/profiler.factor
library/platform/native/random.factor
library/platform/native/strings.factor
library/platform/native/unparser.factor
library/platform/native/vectors.factor
library/prettyprint.factor
library/random.factor
library/sbuf.factor
library/stdio-binary.factor
library/strings.factor
library/test/benchmark/empty-loop.factor
library/test/benchmark/sort.factor
library/test/continuations.factor
library/test/hashtables.factor
library/test/io/no-trailing-eol.factor
library/test/jvm-compiler/auxiliary.factor
library/test/jvm-compiler/compiler-types.factor
library/test/jvm-compiler/compiler.factor
library/test/jvm-compiler/inference.factor
library/test/jvm-compiler/miscellaneous.factor
library/test/jvm-compiler/tail.factor
library/test/jvm-compiler/types.factor
library/test/lists/assoc.factor
library/test/lists/java.factor
library/test/lists/lists.factor
library/test/math/bignum.factor
library/test/math/bitops.factor
library/test/math/complex.factor
library/test/math/float.factor
library/test/math/gcd.factor
library/test/math/irrational.factor
library/test/math/rational.factor
library/test/math/simpson.factor
library/test/namespaces/java.factor
library/test/parse-number.factor
library/test/random.factor
library/test/strings.factor
library/test/test.factor
library/test/vectors.factor
library/test/words.factor
library/vector-combinators.factor
library/vectors.factor
native/arithmetic.c
native/arithmetic.h
native/factor.h
native/fixnum.c
native/io.h
native/memory.c
native/primitives.c
native/primitives.h

index fa7fcb863c941539e581b33b77ee6d16d85a4cab..7db6c076d8ef9133c6ea309ed307a3807e611d61 100644 (file)
@@ -35,7 +35,7 @@ USE: strings
     rect> dup CHAR: ~ mandel-step >char write ;
 
 : mandel-y ( y -- )
-    75 [ dupd 25 / 2 - >float swap mandel-x ] times* drop terpri ;
+    75 [ dupd 25 / 2 - swap mandel-x ] times* drop terpri ;
 
 : mandel ( -- )
-    21 [ 10 / 1 - >float mandel-y ] times* ;
+    21 [ 10 / 1 - mandel-y ] times* ;
index 4e3cfbf39a0923f49f857bc4481dce48d80c9571..03193a2b63a33cb8c1f9fba0868ba3f5e70cecfc 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: cross-compiler
-USE: arithmetic
 USE: kernel
 USE: lists
+USE: math
 USE: namespaces
 USE: parser
 USE: real-math
@@ -40,10 +40,6 @@ USE: vectors
 USE: vectors
 USE: words
 
-IN: arithmetic
-DEFER: number=
-DEFER: /i
-
 IN: kernel
 DEFER: getenv
 DEFER: setenv
@@ -79,6 +75,10 @@ DEFER: add-write-io-task
 DEFER: write-fd-8
 DEFER: next-io-task
 
+IN: math
+DEFER: number=
+DEFER: /i
+
 IN: parser
 DEFER: str>float
 
@@ -177,7 +177,6 @@ IN: cross-compiler
         <=
         >
         >=
-        gcd
         facos
         fasin
         fatan
index 5c6468014568bfab563b7afe39b04ca41ebfcd19..d68c5a812b5f8ac5c8bc65823a88ac49e96ebb72 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: errors
-USE: arithmetic
 USE: combinators
 USE: continuations
 USE: kernel
 USE: lists
+USE: math
 USE: namespaces
 USE: stack
 USE: strings
index 41b2c669975831851291e29edcc0119f848a3032..8c36191965454b8cde636c0f75aa5c2a9d86a30f 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: format
-USE: arithmetic
 USE: combinators
 USE: kernel
+USE: math
 USE: namespaces
 USE: strings
 USE: stack
index 7defd1194f6ef116ce4003ca8eac6247089a6b6e..d64faf75fe3aa6e2e8d24216ad38d033af0f903a 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: hashtables
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
+USE: math
 USE: stack
 USE: vectors
 
index f31da9fdec1e571777802a880afb14c2e3f21dde..a7ac65b4d1b5fc8db9c42ae63a656d4e0db2014a 100644 (file)
@@ -26,7 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: httpd
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: httpd-responder
@@ -34,6 +33,7 @@ USE: kernel
 USE: lists
 USE: logging
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: stdio
index 0f5b839ab7e8dabc236cc1563cee7fb1cf593472..3a657ace236488a071b6476be285fe110e6e7e47 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: url-encoding
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: logic
 USE: format
+USE: math
 USE: parser
 USE: stack
 USE: strings
index 60035a2b12cea29f2f032495466fc8cc113861c0..aeecb3ad9fd3c4fe7b034e023b6bf48ecfd1fee3 100644 (file)
@@ -26,7 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: cross-compiler
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: format
@@ -34,6 +33,7 @@ USE: hashtables
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: prettyprint
 USE: stack
index 226fed735c04983ed2dea1cdf50014aaa8915dac..9dcf9cf6fce3ba6c66845f3676c84c84e9a5754d 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: interpreter
-USE: arithmetic
 USE: combinators
 USE: continuations
 USE: errors
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: parser
 USE: stack
index 516b2613cea0715a2a39324a36863551d49fb50b..670105f0201e5bf696cd922ef06aeb5f4d2615a4 100644 (file)
@@ -26,8 +26,8 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: jedit
-USE: arithmetic
 USE: combinators
+USE: math
 USE: namespaces
 USE: stack
 USE: strings
index 9e86e7bbfc18ea96b65323d5a9bcf8f9d46daf0e..d374b14bd40218d320328752c9b3d98bb54fe715 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: jedit
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: kernel
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: stdio
index fbb332da3fdb957e86b640d6ea1a2b523da4c736..0350d7e8303adcc9ffa3e76f70c0835d7d55db46 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: lists
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: logic
+USE: math
 USE: stack
 USE: vectors
 
index b93510337cbbbbe56d64350856db706aaed9f475..2dc8a22ae24f74d81fb48e43623d2a9e724764d4 100644 (file)
@@ -26,8 +26,8 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: combinators
+USE: math
 USE: real-math
 USE: stack
 
index e9750fea85bfed971c5a72dbbb9f78464ef6a229..78286e5d76d4a550edfbcff3f472d6a313074789 100644 (file)
@@ -25,7 +25,7 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: arithmetic
+IN: math
 USE: combinators
 USE: kernel
 USE: logic
index 13b0c2269110ec7009da50e12c2a8551711caabb..5fe49d3cca3947a649edfc7d4b624b1c0dbe412a 100644 (file)
@@ -26,8 +26,8 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: lists
+USE: math
 USE: stack
 
 : |+ ( list -- sum )
index 2a3fa66abf28d1bdaa2df39ea6c95583ef0a51f2..ee234742f257e9cd5e03092c1b53567f2588181f 100644 (file)
@@ -25,7 +25,7 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: arithmetic
+IN: math
 USE: combinators
 USE: kernel
 USE: stack
index 38f3aaeac47bac41e6b47f2d138187d887220596..ecc3897a6a6658150e15af3ebc032f2517f53b2d 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: logic
+USE: math
 USE: real-math
 USE: stack
 
@@ -57,7 +57,11 @@ USE: stack
 
 : abs ( z -- abs )
     #! Compute the complex absolute value.
-    >rect mag2 ; inline
+    dup complex? [
+        >rect mag2
+    ] [
+        dup 0 < [ neg ] when
+    ] ifte ;
 
 : conjugate ( z -- z* )
     >rect neg rect> ;
index ceaaecdda4258955442d16f5aeab4fe8e9e8aaad..3283946428d30fda222be64751b7121cd592092f 100644 (file)
@@ -25,7 +25,7 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: arithmetic
+IN: math
 USE: combinators
 USE: logic
 USE: namespaces
index b65ec754b2a209461b5493a6c83765bc00231c6e..d4e3abc302d6f0ce387e1699d57a8a64e18bce5d 100644 (file)
@@ -26,8 +26,8 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: combinators
+USE: math
 USE: real-math
 USE: kernel
 USE: stack
index f7587bb7ffd4647984227262ea2abff41274c83e..8200316bdac53e1084a104033565b1736c349929 100644 (file)
@@ -26,8 +26,8 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: combinators
+USE: math
 USE: stack
 
 : quadratic-complete ( a b c -- a b c a b )
index 25d2afa10caa9a869573deedc422f7fb930a1878..963d0ad707f1220932ddee58f346ffe7d0a6398d 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: stack
 
 : multiplier ( n -- 2|4 )
index 70c4e040ceff261760318c2d6efa04c45138a4a6..e7509f127ce37dbe2ebe9999a6c165d61dc6139b 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: math
-USE: arithmetic
 USE: combinators
 USE: kernel
+USE: math
 USE: real-math
 USE: stack
 
index 57d959e344241812b56d1d0ceae0b63aa435ad42..55130dc862df7fc7d99e61cdb2497e20d5fb3d27 100644 (file)
@@ -25,7 +25,7 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: arithmetic
+IN: math
 USE: combinators
 USE: kernel
 USE: logic
index aeaea0957b181d0d7b83ffeff891bf50b86a61ac..d81cf75cccf3708e6b4cb113f244527a117b118f 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: cross-compiler
-USE: arithmetic
 USE: kernel
 USE: lists
+USE: math
 USE: parser
 USE: stack
 USE: stdio
index d8bb18dad643b3f08a59e056d1b5085d04bb597b..b8b0dccb731d747fbefd728cdb894ceb6043d550 100644 (file)
@@ -82,7 +82,7 @@ IN: kernel
 : garbage-collection ( -- )
     [ ] "java.lang.System" "gc" jinvoke-static ;
 
-IN: arithmetic
+IN: math
 DEFER: >bignum
 
 IN: kernel
@@ -106,10 +106,12 @@ IN: kernel
 
 : free-memory ( -- int )
   #! Return the free memory in the JVM.
-  jvm-runtime f "java.lang.Runtime" "freeMemory" jinvoke ;
+  jvm-runtime f "java.lang.Runtime" "freeMemory" jinvoke
+  >bignum ;
 
 : total-memory ( -- int )
   #! Return the total memory available to the JVM.
-  jvm-runtime f "java.lang.Runtime" "totalMemory" jinvoke ;
+  jvm-runtime f "java.lang.Runtime" "totalMemory" jinvoke
+  >bignum ;
 
 : room free-memory total-memory ;
index 2958193175fe405476df42702240d6a0afbcd4f9..3e5593360249e65fec85f3d3a585c2ab3cd1a2e1 100644 (file)
@@ -25,7 +25,7 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: arithmetic
+IN: math
 USE: combinators
 USE: kernel
 USE: logic
index b9183f02de41185ff669a1b5424641cbda7d9134..1545e242f7ddb66096c19b1e1d9021e5b6f0f0ad 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: prettyprint
-USE: arithmetic
 USE: combinators
 USE: lists
+USE: math
 USE: prettyprint
 USE: stack
 USE: stdio
index 592ab21af4822fce2fdd9f04be41d0d5b0b7d250..393b03be49cf0a0fea7b82900bdb0f46fada7e65 100644 (file)
@@ -31,8 +31,8 @@
 !!! 'math' vocabulary instead.
 
 IN: real-math
-USE: arithmetic
 USE: kernel
+USE: math
 USE: stack
 
 : facos ( x -- acos )
index a11f92c063abcbbda8c62f44d1547f89116dd175..07ff543acc88b989384455c232dfebf31ef696ac 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: regexp
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: logic
 USE: lists
+USE: math
 USE: stack
 
 : <regex> ( pattern -- regex )
index 03ad5eb760eebcc4d088704a71ed94c779e1ab50..be1de3629f1c022f9e6433d51382866c1d50655c 100644 (file)
@@ -82,6 +82,7 @@ USE: stdio
     "/library/platform/native/init.factor"
 
     "/library/math/math.factor"
+    "/library/platform/native/math.factor"
     "/library/math/pow.factor"
     "/library/math/trig-hyp.factor"
     "/library/math/arc-trig-hyp.factor"
index ee1ccdab1cdee71b9f6203f9300a94a74f34c2ef..c2979a17fdf428b27634021496a9ad89a98eb337 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: errors
-USE: arithmetic
 USE: combinators
 USE: continuations
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: prettyprint
 USE: stack
@@ -77,7 +77,7 @@ USE: vectors
     " with " write unparse print ;
 
 : float-format-error ( list -- )
-    "Invalid floating point literal format: " write car . ;
+    "Invalid floating point literal format: " write . ;
 
 : signal-error ( obj -- )
     "Operating system signal " write . ;
index 5441dbfa2bea6a652abb051d4c610862fb6966bc..dfebc48f5272506058fffd09bb193ffb9875ada6 100644 (file)
@@ -29,12 +29,12 @@ IN: vectors
 DEFER: vector=
 
 IN: kernel
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: io-internals
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: stdio
diff --git a/library/platform/native/math.factor b/library/platform/native/math.factor
new file mode 100644 (file)
index 0000000..1ef8121
--- /dev/null
@@ -0,0 +1,39 @@
+! :folding=indent:collapseFolds=0:
+
+! $Id$
+!
+! Copyright (C) 2004 Slava Pestov.
+! 
+! Redistribution and use in source and binary forms, with or without
+! modification, are permitted provided that the following conditions are met:
+! 
+! 1. Redistributions of source code must retain the above copyright notice,
+!    this list of conditions and the following disclaimer.
+! 
+! 2. Redistributions in binary form must reproduce the above copyright notice,
+!    this list of conditions and the following disclaimer in the documentation
+!    and/or other materials provided with the distribution.
+! 
+! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+IN: math
+USE: combinators
+USE: kernel
+USE: stack
+
+: (gcd) ( x y -- z )
+    USE: prettyprint .s
+    dup 0 = [ drop ] [ tuck mod (gcd) ] ifte ;
+
+: gcd ( x y -- z )
+    #! Greatest common divisor.
+    abs swap abs 2dup < [ swap ] when (gcd) ;
index 3917add151831dc992298f8ee5513e6a3d1d4d6d..d7ad13e054386f2c78ce13e6e302a16395ebc3c0 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: namespaces
-USE: arithmetic
 USE: combinators
 USE: hashtables
 USE: kernel
 USE: lists
+USE: math
 USE: stack
 USE: strings
 USE: vectors
index e887fc5d957573d092ed13756cd436b8f4d862cf..bfc4b6bdcba3675973fd7b06f807afc3acaa1d89 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: parser
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: strings
index 1ae15f03ca0a290e735b5894b30d99f3daf11704..cdbe65b2495756d734efe10abb99fb05ce3c64ea 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: parser
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: kernel
 USE: lists
+USE: math
 USE: namespaces
 USE: stack
 USE: stdio
index 7e67536930df700402090050d8c122d7f0612776..a0972c98091dee9c0c19c3ed72d67a196da3e858 100644 (file)
 ! that it does not contain Java words anymore!
 IN: builtins
 
-USE: arithmetic
 USE: combinators
 USE: cross-compiler
 USE: errors
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: parser
 USE: stack
index de50359e3ed0a94277fbb16739482cc7ac0d48ee..643118e4ea131ff157c61a37a70382fae88c2002 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: parser
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: strings
index 5cecf8561428fbe37ce5ccaba7118144a6bfd52b..aab8b89ed6f4380e9cb04b15a759c4cf1297090d 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: profiler
-USE: arithmetic
 USE: kernel
 USE: lists
+USE: math
 USE: prettyprint
 USE: stack
 USE: words
index 278ebfdbb138974b18396fc2aeffd275686e4b57..1fc064de8954ef9e57ddc4037bf8c569a8d2df5c 100644 (file)
@@ -26,8 +26,8 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: random
-USE: arithmetic
 USE: kernel
+USE: math
 USE: stack
 
 : power-of-2? ( n -- ? )
index d1f99fff358c511126191319514b7216f515d869..5e512e25574a66777f017229d65d4b76694491bf 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: strings
-USE: arithmetic
 USE: kernel
 USE: logic
+USE: math
 USE: stack
 
 : cat2 ( "a" "b" -- "ab" )
index a5429efad0e4e66e581092572f56f725a5129d60..fe9e9f14a07bb515109c41f2f4988cde306b506c 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: unparser
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: format
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: parser
 USE: stack
index e65e4dcd15bff332b89842c835ef9b2da437dccb..7508e6743ca17f67ed0788a31d377660afb4d43e 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: vectors
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
+USE: math
 USE: stack
 
 : 2vector-nth ( n vec vec -- obj obj )
index 8f6b8a1308ba18246a16354412ac2470e837efd4..709b4d4473f4c05c9eacc11952541a7f2ad460c0 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: prettyprint
-USE: arithmetic
 USE: combinators
 USE: errors
 USE: format
 USE: kernel
 USE: logic
 USE: lists
+USE: math
 USE: namespaces
 USE: prettyprint
 USE: stack
index f75de33a1aea9d4a52af33dc282d77339665a01c..ef31058884950644af71256bea4cccb242adae5a 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: random
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
+USE: math
 USE: stack
 
 : random-digit ( -- digit )
index 59bf76010295f1501adb34e62c7d968678e5afb1..17542bcac5fc22c753dd2fa3c86ac24a78182895 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: strings
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
+USE: math
 USE: namespaces
 USE: strings
 USE: stack
index 1e9ae23cb471cb319f32a49fb4aaa4c77386d289..51e0296a75bd5094d1d1e7f4c90ceea6d185e040 100644 (file)
@@ -26,7 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: stdio
-USE: arithmetic
+USE: math
 USE: stack
 USE: streams
 USE: strings
index 3c946c3a78b804df04d2692ef07293900acd06ac..63099b9b713333b709ebc5f6ce85afbb3455410f 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: strings
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: stack
 
 : f-or-"" ( obj -- ? )
index ae7fa233a85b3692d08cd48864c23610db454142..87bf850dd2df39cfe964aeddf5a369aeec72a267 100644 (file)
@@ -1,5 +1,5 @@
 IN: scratchpad
-USE: arithmetic
+USE: math
 USE: test
 
 [ 2000000 [ ] times ] time
index a6f7dc5b04fb0428f058e928bd2461c34b4fe62f..ce8daa85ddb514750cb3c6b14f222244837a290a 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: lists
+USE: math
 USE: random
 USE: stack
 USE: test
index 3e32995cc1e8b9c63b93b5f96c3fd1659b9caa64..6159ec0e8e4d232477c715821cc8c11e08eaddc5 100644 (file)
@@ -1,9 +1,9 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: continuations
 USE: kernel
 USE: lists
+USE: math
 USE: namespaces
 USE: stack
 USE: stdio
index c909166947e0335fae5eb054cb8722b01b8d1a9b..05d38e1f82ad27ac419a2ee6ee10091a5c65b8ac 100644 (file)
@@ -1,10 +1,10 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: hashtables
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: test
index 4da8a500b921d5e1f7b9ec45df8dcff84e3d6bbd..8fbf328f5957a3685b6f691c2c5fcc224bd2ae68 100644 (file)
@@ -1,2 +1,2 @@
-USE: arithmetic
+USE: math
 2 2 +
\ No newline at end of file
index 6356e3dc38165c947205c8bb44a03971a6a58f8f..35901fcfb95d8328f5efdeed0fa753e7dbe10ed8 100644 (file)
@@ -1,7 +1,7 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: kernel
+USE: math
 USE: stack
 USE: stdio
 USE: test
index b15fc7b4ea66d9ab8bab33eed70ee8290bfa7400..53206536d705c59b5f79187ea1bc1cd2ae804228 100644 (file)
@@ -1,5 +1,4 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: compiler
 USE: kernel
index d95df6db7efda07bf80583272e0f53468be1c2fb..578a5e3a7c2b8567d76b88209acfdceacfdd06d2 100644 (file)
@@ -1,5 +1,4 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: compiler
 USE: inspector
index 1eb5e583d21f2953fa958800168b43c62583f51e..8b022a94b9eba3e906e511dfb726bae16f95e83a 100644 (file)
@@ -1,5 +1,4 @@
 IN: scratchpad
-USE: arithmetic
 USE: compiler
 USE: lists
 USE: math
index 5db045fc956c6dc39a6fa6da102ca7afc6dc041a..0c81c55cf7703518d29767d110942413da73ef27 100644 (file)
@@ -1,11 +1,11 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: compiler
 USE: continuations
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: random
 USE: stack
index 09034428f8e1c6a461aa77f57ad3b00b72d7ae47..78a643488440a986b2c371d03d007282ef10b23a 100644 (file)
@@ -1,8 +1,8 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: lists
+USE: math
 USE: prettyprint
 USE: stack
 USE: stdio
index 34366c53c7f8b4c1fcceacc7afe5c9a0773596a9..d0133b86437084a11f3d601712d14dcfaa3562c3 100644 (file)
@@ -1,7 +1,7 @@
 IN: scratchpad
-USE: arithmetic
 USE: compiler
 USE: lists
+USE: math
 USE: stack
 USE: stdio
 USE: strings
index e7d88184d6a72f3611cf7c0a2561768d318429c7..26bbc346c7bbcbd9ef3b1349fc1f552a993e7ea8 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: lists
+USE: math
 USE: namespaces
 USE: test
 
index a991bde64d0acc1dee14ec14e4a61934e0356e60..6d59a15afe88630244a4a0f35d1ad33d5d919760 100644 (file)
@@ -1,6 +1,6 @@
-USE: arithmetic
 USE: compiler
 USE: lists
+USE: math
 USE: stack
 USE: strings
 USE: test
index 4f7520f6d97c16cdae45d38a9bdbaca698682506..a6f07b89df040968a3e0dff0035f3b51ebf3dcc3 100644 (file)
@@ -1,8 +1,8 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: stack
 USE: test
index 124653e8c032fae6e0de1ec9a48dba03c4b1c23c..1e17337b8e123f556d9b9070987f50681a2180b1 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: stack
+USE: math
 USE: test
 USE: unparser
 
@@ -17,3 +17,9 @@ unit-test
 [ 4294967296 ] [ 1 16 shift 16 shift ] unit-test
 [ 4294967296 ] [ 1 32 shift ] unit-test
 [ 1267650600228229401496703205376 ] [ 1 100 shift ] unit-test
+[ 268435456 ] [ -268435456 >fixnum -1 / ] unit-test
+[ 268435456 ] [ -268435456 >fixnum -1 /i ] unit-test
+[ 268435456 0 ] [ -268435456 >fixnum -1 /mod ] unit-test
+[ 1/268435456 ] [ -1 -268435456 >fixnum / ] unit-test
+[ 0 ] [ -1 -268435456 >fixnum /i ] unit-test
+[ 0 -1 ] [ -1 -268435456 >fixnum /mod ] unit-test
index 34227ec2c0a61425719718f1691ed95205ab99e0..4e09e60e5f3c0e104137f0d08999c734f6020d02 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
+USE: math
 USE: stack
 USE: test
 
index 7b1f7bdfa1190becd5d2c664b6c284e4d30e8cf2..0565bff62d73a5bd73382f3ed36c4403eade7684 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
+USE: math
 USE: stack
 USE: test
 
index 6830e1306dd2db3c628e944b8cd1826d39c3fcbd..c45e4f458c089e047e37e7983aa58e5f236cba60 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
+USE: math
 USE: stack
 USE: test
 
index fd738e69fbaeccce19397175e5c794cf66960d8d..be81e048b1213af651224bc6ec6a71a3c3edc67e 100644 (file)
@@ -1,5 +1,5 @@
 IN: scratchpad
-USE: arithmetic
+USE: math
 USE: test
 
 [ 100 ] [ 100 100 gcd ] unit-test
@@ -19,3 +19,9 @@ USE: test
 [ 4 ] [ -132 >bignum -64 >bignum gcd ] unit-test
 [ 4 ] [ 132 >bignum -64 >bignum gcd ] unit-test
 [ 4 ] [ -132 >bignum -64 >bignum gcd ] unit-test
+
+[ 6 ] [
+    1326264299060955293181542400000006
+    1591517158873146351817850880000000
+    gcd
+] unit-test
index 1b7c55c420b7f82d249692d6ef9df25726964271..2af5a62b50b552d0f3f553c6fecac21c99ed78cb 100644 (file)
@@ -1,5 +1,4 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
 USE: math
 USE: test
index b9228d7c34c879a23423815fa18c8c64d808f42b..502564add6a7c40d533b13c5defc8725e84fe261 100644 (file)
@@ -1,6 +1,6 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
+USE: math
 USE: stack
 USE: test
 USE: unparser
index d0bfc1cf8161af99603ad82d956c6fbdd24d31d6..4c1b63ef14d6b6d5dee61c2bcca4360f033c5084 100644 (file)
@@ -1,5 +1,4 @@
 IN: scratchpad
-USE: arithmetic
 USE: math
 USE: test
 
index 0b9992233096ba58bb9366d80349d1783ee95fd3..8a73e051f7528b07cc1df498818871375c3b9c09 100644 (file)
@@ -1,7 +1,7 @@
 IN: scratchpad
-USE: arithmetic
 USE: compiler
 USE: kernel
+USE: math
 USE: namespaces
 USE: stack
 USE: test
index 810b126a9cac40b1586e390f8bdec64a8990bc20..3efbf9ac369d4c47195d1041d53896f82790114e 100644 (file)
@@ -1,5 +1,5 @@
 IN: scratchpad
-USE: arithmetic
+USE: math
 USE: parser
 USE: strings
 USE: test
index 666fdea9be8279de7f6a1c24bae90ad043168a1e..2373f05df5abb282a3c8313919b7b616d8c70cd0 100644 (file)
@@ -1,8 +1,8 @@
 IN: scratchpad
-USE: arithmetic
 USE: kernel
 USE: lists
 USE: logic
+USE: math
 USE: namespaces
 USE: random
 USE: stack
index 86084eae6e1693eb29732e0438af3a5cafe71b55..e564822a03ebd5d6ef8dba197d134966ddac9e7d 100644 (file)
@@ -1,7 +1,7 @@
 IN: scratchpad
-USE: arithmetic
 USE: combinators
 USE: kernel
+USE: math
 USE: namespaces
 USE: stack
 USE: strings
index b250cea605e4c25eb74823e35de7fb4653d249f5..d1584e1584c83b3f127a41ee75e671cb5b2e0f7a 100644 (file)
@@ -3,12 +3,12 @@
 ! Some of these words should be moved to the standard library.
 
 IN: test
-USE: arithmetic
 USE: combinators
 USE: compiler
 USE: errors
 USE: kernel
 USE: lists
+USE: math
 USE: namespaces
 USE: parser
 USE: prettyprint
@@ -22,7 +22,7 @@ USE: unparser
     [ "Assertion failed!" throw ] unless ;
 
 : print-test ( input output -- )
-    "TESTING: " write 2list . ;
+    "TESTING: " write 2list . flush ;
 
 : keep-datastack ( quot -- )
     datastack >r call r> set-datastack drop ;
index be0e7e39fb2d98b2ea15df492f31a821a8f1fa06..33098e517d639dbd0a68061617ee1f025d4f2e48 100644 (file)
@@ -1,6 +1,6 @@
-USE: arithmetic
 USE: lists
 USE: kernel
+USE: math
 USE: random
 USE: stack
 USE: test
index 48e62cebbc19bbcbf4704004c0c2fcb58dba556b..3332f175d0c6b882d9494cd1fb15b537b2f8a581 100644 (file)
@@ -1,5 +1,5 @@
 IN: scratchpad
-USE: arithmetic
+USE: math
 USE: test
 USE: words
 
index 68e79c2446a980e7a90e000068e2f42d04a3d41b..ef6e023e7d6b0f228e2a66e554180f4019e4a519 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: vectors
-USE: arithmetic
 USE: combinators
 USE: kernel
 USE: logic
+USE: math
 USE: stack
 
 : vector-each ( vector code -- )
index 058a3c7d79d661d00f2bb67f646b32f01c6168fb..516ba187b1876d42fe272c1a399dd50fdc032ef8 100644 (file)
@@ -26,9 +26,9 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: vectors
-USE: arithmetic
 USE: kernel
 USE: lists
+USE: math
 USE: stack
 
 : empty-vector ( len -- vec )
index 8a724db56b7c2c4c1b06647fa0c5a44bb41fe306..b52664e90db4aaaf993d0e6863bd44f281570fba 100644 (file)
@@ -1,5 +1,13 @@
 #include "factor.h"
 
+CELL tag_fixnum_or_bignum(FIXNUM x)
+{
+       if(x < FIXNUM_MIN || x > FIXNUM_MAX)
+               return tag_object(s48_long_to_bignum(x));
+       else
+               return tag_fixnum(x);
+}
+
 CELL upgraded_arithmetic_type(CELL type1, CELL type2)
 {
        switch(type1)
@@ -193,10 +201,6 @@ BINARY_OP(greater)
 BINARY_OP_NUMBER_ONLY(greatereq)
 BINARY_OP(greatereq)
 
-BINARY_OP_INTEGER_ONLY(gcd)
-BINARY_OP_NUMBER_ONLY(gcd)
-BINARY_OP(gcd)
-
 UNARY_OP_INTEGER_ONLY(not)
 UNARY_OP_NUMBER_ONLY(not)
 UNARY_OP(not)
index 841ce90f6f2a004dbbc4e74dcff63d0333457fb0..78cf557ccd26ffa3873cd800e60ee6cd1d62bf8a 100644 (file)
@@ -9,12 +9,7 @@ RATIO* bignum_to_ratio(CELL n);
 FLOAT* bignum_to_float(CELL n);
 FLOAT* ratio_to_float(CELL n);
 
-#define CELL_TO_INTEGER(result) \
-       FIXNUM _result = (result); \
-       if(_result < FIXNUM_MIN || _result > FIXNUM_MAX) \
-               return tag_object(s48_long_to_bignum(_result)); \
-       else \
-               return tag_fixnum(_result);
+CELL tag_fixnum_or_bignum(FIXNUM x);
 
 #define BINARY_OP(OP) \
 CELL OP(CELL x, CELL y) \
index 7d9099021fb5d52928b1483132d3cb77d2592468..be30f7c8dc56fc80bceef33a68b0c309b5d67a5a 100644 (file)
 
 /* CELL must be 32 bits and your system must have 32-bit pointers */
 typedef unsigned long int CELL;
-#define CELLS sizeof(CELL)
+#define CELLS ((signed)sizeof(CELL))
 
 /* must always be 16 bits */
 typedef unsigned short CHAR;
-#define CHARS sizeof(CHAR)
+#define CHARS ((signed)sizeof(CHAR))
 
 /* Memory heap size */
 #define DEFAULT_ARENA (5 * 1024 * 1024)
index cfd7545dd585f21a1cc989c455dda3b262b4bf1c..02df81396b7cd3394919e226366f6816dadab6a4 100644 (file)
@@ -40,12 +40,14 @@ CELL number_eq_fixnum(CELL x, CELL y)
 
 CELL add_fixnum(CELL x, CELL y)
 {
-       CELL_TO_INTEGER(untag_fixnum_fast(x) + untag_fixnum_fast(y));
+       return tag_fixnum_or_bignum(untag_fixnum_fast(x)
+               + untag_fixnum_fast(y));
 }
 
 CELL subtract_fixnum(CELL x, CELL y)
 {
-       CELL_TO_INTEGER(untag_fixnum_fast(x) - untag_fixnum_fast(y));
+       return tag_fixnum_or_bignum(untag_fixnum_fast(x)
+               - untag_fixnum_fast(y));
 }
 
 CELL multiply_fixnum(CELL _x, CELL _y)
@@ -67,7 +69,7 @@ CELL divint_fixnum(CELL x, CELL y)
 {
        /* division takes common factor of 8 out. */
        /* we have to do SIGNED division here */
-       return tag_fixnum((FIXNUM)x / (FIXNUM)y);
+       return tag_fixnum_or_bignum((FIXNUM)x / (FIXNUM)y);
 }
 
 CELL divfloat_fixnum(CELL x, CELL y)
@@ -79,17 +81,19 @@ CELL divfloat_fixnum(CELL x, CELL y)
        return tag_object(make_float((double)_x / (double)_y));
 }
 
-CELL divmod_fixnum(CELL x, CELL y)
+CELL divmod_fixnum(CELL _x, CELL _y)
 {
-       ldiv_t q = ldiv(x,y);
-       /* division takes common factor of 8 out. */
-       dpush(tag_fixnum(q.quot));
-       return q.rem;
+       FIXNUM x = untag_fixnum_fast(_x);
+       FIXNUM y = untag_fixnum_fast(_y);
+       dpush(tag_fixnum_or_bignum(x / y));
+       return tag_fixnum_or_bignum(x % y);
 }
 
-CELL mod_fixnum(CELL x, CELL y)
+CELL mod_fixnum(CELL _x, CELL _y)
 {
-       return x % y;
+       FIXNUM x = untag_fixnum_fast(_x);
+       FIXNUM y = untag_fixnum_fast(_y);
+       return tag_fixnum(x % y);
 }
 
 FIXNUM gcd_fixnum(FIXNUM x, FIXNUM y)
@@ -141,9 +145,13 @@ CELL divide_fixnum(CELL x, CELL y)
        }
 
        if(_y == 1)
-               return tag_fixnum(_x);
+               return tag_fixnum_or_bignum(_x);
        else
-               return tag_ratio(ratio(tag_fixnum(_x),tag_fixnum(_y)));
+       {
+               return tag_ratio(ratio(
+                       tag_fixnum_or_bignum(_x),
+                       tag_fixnum_or_bignum(_y)));
+       }
 }
 
 CELL and_fixnum(CELL x, CELL y)
@@ -164,7 +172,7 @@ CELL xor_fixnum(CELL x, CELL y)
 CELL shift_fixnum(CELL _x, FIXNUM y)
 {
        FIXNUM x = untag_fixnum_fast(_x);
-       if(y > CELLS * -8 && y < CELLS * 8)
+       if(y > -CELLS * 8 && y < CELLS * 8)
        {
                long long result = (y < 0
                        ? (long long)x >> -y
index 089e63ff600447afeb64070c920176f35c28bc4a..31a792131de69a58d6ee319c9ab02e2e6e6090e4 100644 (file)
@@ -1,3 +1,5 @@
+FILE* debug_fd;
+
 typedef enum {
        IO_TASK_READ_LINE,
        IO_TASK_READ_COUNT,
index d699a28a913e5f267f2bd1e3b3b0685232b497ca..d57507a9dc4e6761501d00edceced3a9c0afc7e7 100644 (file)
@@ -46,10 +46,11 @@ void check_memory(void)
        {
                if(active->here > active->limit)
                {
-                       printf("Out of memory\n");
-                       printf("active->base  = %ld\n",active->base);
-                       printf("active->here  = %ld\n",active->here);
-                       printf("active->limit = %ld\n",active->limit);
+                       fprintf(stderr,"Out of memory\n");
+                       fprintf(stderr,"active->base  = %ld\n",active->base);
+                       fprintf(stderr,"active->here  = %ld\n",active->here);
+                       fprintf(stderr,"active->limit = %ld\n",active->limit);
+                       fflush(stderr);
                        exit(1);
                }
 
index 63f3cc4100f777546b110e757642c6ba27cce385..f2fadc14bcd97b162047b73b230821d5d4cd541e 100644 (file)
@@ -73,7 +73,6 @@ XT primitives[] = {
        primitive_lesseq,
        primitive_greater,
        primitive_greatereq,
-       primitive_gcd,
        primitive_facos,
        primitive_fasin,
        primitive_fatan,
index 9990a9d11ebe2ee9c1cf058d020ac954e1329d3b..baeaa8997b58e4a658321a683cdcb3ee06ba0162 100644 (file)
@@ -1,4 +1,4 @@
 extern XT primitives[];
-#define PRIMITIVE_COUNT 141
+#define PRIMITIVE_COUNT 140
 
 CELL primitive_to_xt(CELL primitive);