diff --git a/contrib/mandel.factor b/contrib/mandel.factor index fa7fcb863c..7db6c076d8 100644 --- a/contrib/mandel.factor +++ b/contrib/mandel.factor @@ -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* ; diff --git a/library/cross-compiler.factor b/library/cross-compiler.factor index 4e3cfbf39a..03193a2b63 100644 --- a/library/cross-compiler.factor +++ b/library/cross-compiler.factor @@ -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 diff --git a/library/errors.factor b/library/errors.factor index 5c64680145..d68c5a812b 100644 --- a/library/errors.factor +++ b/library/errors.factor @@ -26,11 +26,11 @@ ! 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 diff --git a/library/format.factor b/library/format.factor index 41b2c66997..8c36191965 100644 --- a/library/format.factor +++ b/library/format.factor @@ -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 diff --git a/library/hashtables.factor b/library/hashtables.factor index 7defd1194f..d64faf75fe 100644 --- a/library/hashtables.factor +++ b/library/hashtables.factor @@ -26,10 +26,10 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: hashtables -USE: arithmetic USE: combinators USE: kernel USE: lists +USE: math USE: stack USE: vectors diff --git a/library/httpd/httpd.factor b/library/httpd/httpd.factor index f31da9fdec..a7ac65b4d1 100644 --- a/library/httpd/httpd.factor +++ b/library/httpd/httpd.factor @@ -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 diff --git a/library/httpd/url-encoding.factor b/library/httpd/url-encoding.factor index 0f5b839ab7..3a657ace23 100644 --- a/library/httpd/url-encoding.factor +++ b/library/httpd/url-encoding.factor @@ -26,11 +26,11 @@ ! 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 diff --git a/library/image.factor b/library/image.factor index 60035a2b12..aeecb3ad9f 100644 --- a/library/image.factor +++ b/library/image.factor @@ -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 diff --git a/library/interpreter.factor b/library/interpreter.factor index 226fed735c..9dcf9cf6fc 100644 --- a/library/interpreter.factor +++ b/library/interpreter.factor @@ -26,13 +26,13 @@ ! 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 diff --git a/library/jedit/jedit-local.factor b/library/jedit/jedit-local.factor index 516b2613ce..670105f020 100644 --- a/library/jedit/jedit-local.factor +++ b/library/jedit/jedit-local.factor @@ -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 diff --git a/library/jedit/jedit.factor b/library/jedit/jedit.factor index 9e86e7bbfc..d374b14bd4 100644 --- a/library/jedit/jedit.factor +++ b/library/jedit/jedit.factor @@ -26,11 +26,11 @@ ! 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 diff --git a/library/lists.factor b/library/lists.factor index fbb332da3f..0350d7e830 100644 --- a/library/lists.factor +++ b/library/lists.factor @@ -26,10 +26,10 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: lists -USE: arithmetic USE: combinators USE: kernel USE: logic +USE: math USE: stack USE: vectors diff --git a/library/math/arc-trig-hyp.factor b/library/math/arc-trig-hyp.factor index b93510337c..2dc8a22ae2 100644 --- a/library/math/arc-trig-hyp.factor +++ b/library/math/arc-trig-hyp.factor @@ -26,8 +26,8 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: math -USE: arithmetic USE: combinators +USE: math USE: real-math USE: stack diff --git a/library/math/arithmetic.factor b/library/math/arithmetic.factor index e9750fea85..78286e5d76 100644 --- a/library/math/arithmetic.factor +++ b/library/math/arithmetic.factor @@ -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 diff --git a/library/math/list-math.factor b/library/math/list-math.factor index 13b0c22691..5fe49d3cca 100644 --- a/library/math/list-math.factor +++ b/library/math/list-math.factor @@ -26,8 +26,8 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: math -USE: arithmetic USE: lists +USE: math USE: stack : |+ ( list -- sum ) diff --git a/library/math/math-combinators.factor b/library/math/math-combinators.factor index 2a3fa66abf..ee234742f2 100644 --- a/library/math/math-combinators.factor +++ b/library/math/math-combinators.factor @@ -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 diff --git a/library/math/math.factor b/library/math/math.factor index 38f3aaeac4..ecc3897a6a 100644 --- a/library/math/math.factor +++ b/library/math/math.factor @@ -26,10 +26,10 @@ ! 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> ; diff --git a/library/math/namespace-math.factor b/library/math/namespace-math.factor index ceaaecdda4..3283946428 100644 --- a/library/math/namespace-math.factor +++ b/library/math/namespace-math.factor @@ -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 diff --git a/library/math/pow.factor b/library/math/pow.factor index b65ec754b2..d4e3abc302 100644 --- a/library/math/pow.factor +++ b/library/math/pow.factor @@ -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 diff --git a/library/math/quadratic.factor b/library/math/quadratic.factor index f7587bb7ff..8200316bda 100644 --- a/library/math/quadratic.factor +++ b/library/math/quadratic.factor @@ -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 ) diff --git a/library/math/simpson.factor b/library/math/simpson.factor index 25d2afa10c..963d0ad707 100644 --- a/library/math/simpson.factor +++ b/library/math/simpson.factor @@ -26,11 +26,11 @@ ! 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 ) diff --git a/library/math/trig-hyp.factor b/library/math/trig-hyp.factor index 70c4e040ce..e7509f127c 100644 --- a/library/math/trig-hyp.factor +++ b/library/math/trig-hyp.factor @@ -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 diff --git a/library/platform/jvm/arithmetic.factor b/library/platform/jvm/arithmetic.factor index 57d959e344..55130dc862 100644 --- a/library/platform/jvm/arithmetic.factor +++ b/library/platform/jvm/arithmetic.factor @@ -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 diff --git a/library/platform/jvm/cross-compiler.factor b/library/platform/jvm/cross-compiler.factor index aeaea0957b..d81cf75ccc 100644 --- a/library/platform/jvm/cross-compiler.factor +++ b/library/platform/jvm/cross-compiler.factor @@ -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 diff --git a/library/platform/jvm/kernel.factor b/library/platform/jvm/kernel.factor index d8bb18dad6..b8b0dccb73 100644 --- a/library/platform/jvm/kernel.factor +++ b/library/platform/jvm/kernel.factor @@ -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 ; diff --git a/library/platform/jvm/math-types.factor b/library/platform/jvm/math-types.factor index 2958193175..3e55933602 100644 --- a/library/platform/jvm/math-types.factor +++ b/library/platform/jvm/math-types.factor @@ -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 diff --git a/library/platform/jvm/prettyprint.factor b/library/platform/jvm/prettyprint.factor index b9183f02de..1545e242f7 100644 --- a/library/platform/jvm/prettyprint.factor +++ b/library/platform/jvm/prettyprint.factor @@ -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 diff --git a/library/platform/jvm/real-math.factor b/library/platform/jvm/real-math.factor index 592ab21af4..393b03be49 100644 --- a/library/platform/jvm/real-math.factor +++ b/library/platform/jvm/real-math.factor @@ -31,8 +31,8 @@ !!! 'math' vocabulary instead. IN: real-math -USE: arithmetic USE: kernel +USE: math USE: stack : facos ( x -- acos ) diff --git a/library/platform/jvm/regexp.factor b/library/platform/jvm/regexp.factor index a11f92c063..07ff543acc 100644 --- a/library/platform/jvm/regexp.factor +++ b/library/platform/jvm/regexp.factor @@ -26,11 +26,11 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: regexp -USE: arithmetic USE: combinators USE: kernel USE: logic USE: lists +USE: math USE: stack : ( pattern -- regex ) diff --git a/library/platform/native/boot-stage2.factor b/library/platform/native/boot-stage2.factor index 03ad5eb760..be1de3629f 100644 --- a/library/platform/native/boot-stage2.factor +++ b/library/platform/native/boot-stage2.factor @@ -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" diff --git a/library/platform/native/debugger.factor b/library/platform/native/debugger.factor index ee1ccdab1c..c2979a17fd 100644 --- a/library/platform/native/debugger.factor +++ b/library/platform/native/debugger.factor @@ -26,12 +26,12 @@ ! 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 . ; diff --git a/library/platform/native/kernel.factor b/library/platform/native/kernel.factor index 5441dbfa2b..dfebc48f52 100644 --- a/library/platform/native/kernel.factor +++ b/library/platform/native/kernel.factor @@ -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 index 0000000000..1ef8121532 --- /dev/null +++ b/library/platform/native/math.factor @@ -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) ; diff --git a/library/platform/native/namespaces.factor b/library/platform/native/namespaces.factor index 3917add151..d7ad13e054 100644 --- a/library/platform/native/namespaces.factor +++ b/library/platform/native/namespaces.factor @@ -26,11 +26,11 @@ ! 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 diff --git a/library/platform/native/parse-numbers.factor b/library/platform/native/parse-numbers.factor index e887fc5d95..bfc4b6bdcb 100644 --- a/library/platform/native/parse-numbers.factor +++ b/library/platform/native/parse-numbers.factor @@ -26,12 +26,12 @@ ! 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 diff --git a/library/platform/native/parse-stream.factor b/library/platform/native/parse-stream.factor index 1ae15f03ca..cdbe65b249 100644 --- a/library/platform/native/parse-stream.factor +++ b/library/platform/native/parse-stream.factor @@ -26,11 +26,11 @@ ! 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 diff --git a/library/platform/native/parse-syntax.factor b/library/platform/native/parse-syntax.factor index 7e67536930..a0972c9809 100644 --- a/library/platform/native/parse-syntax.factor +++ b/library/platform/native/parse-syntax.factor @@ -29,13 +29,13 @@ ! 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 diff --git a/library/platform/native/parser.factor b/library/platform/native/parser.factor index de50359e3e..643118e4ea 100644 --- a/library/platform/native/parser.factor +++ b/library/platform/native/parser.factor @@ -26,12 +26,12 @@ ! 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 diff --git a/library/platform/native/profiler.factor b/library/platform/native/profiler.factor index 5cecf85614..aab8b89ed6 100644 --- a/library/platform/native/profiler.factor +++ b/library/platform/native/profiler.factor @@ -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 diff --git a/library/platform/native/random.factor b/library/platform/native/random.factor index 278ebfdbb1..1fc064de89 100644 --- a/library/platform/native/random.factor +++ b/library/platform/native/random.factor @@ -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 -- ? ) diff --git a/library/platform/native/strings.factor b/library/platform/native/strings.factor index d1f99fff35..5e512e2557 100644 --- a/library/platform/native/strings.factor +++ b/library/platform/native/strings.factor @@ -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" ) diff --git a/library/platform/native/unparser.factor b/library/platform/native/unparser.factor index a5429efad0..fe9e9f14a0 100644 --- a/library/platform/native/unparser.factor +++ b/library/platform/native/unparser.factor @@ -26,12 +26,12 @@ ! 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 diff --git a/library/platform/native/vectors.factor b/library/platform/native/vectors.factor index e65e4dcd15..7508e6743c 100644 --- a/library/platform/native/vectors.factor +++ b/library/platform/native/vectors.factor @@ -26,10 +26,10 @@ ! 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 ) diff --git a/library/prettyprint.factor b/library/prettyprint.factor index 8f6b8a1308..709b4d4473 100644 --- a/library/prettyprint.factor +++ b/library/prettyprint.factor @@ -26,13 +26,13 @@ ! 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 diff --git a/library/random.factor b/library/random.factor index f75de33a1a..ef31058884 100644 --- a/library/random.factor +++ b/library/random.factor @@ -26,10 +26,10 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: random -USE: arithmetic USE: combinators USE: kernel USE: lists +USE: math USE: stack : random-digit ( -- digit ) diff --git a/library/sbuf.factor b/library/sbuf.factor index 59bf760102..17542bcac5 100644 --- a/library/sbuf.factor +++ b/library/sbuf.factor @@ -26,10 +26,10 @@ ! 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 diff --git a/library/stdio-binary.factor b/library/stdio-binary.factor index 1e9ae23cb4..51e0296a75 100644 --- a/library/stdio-binary.factor +++ b/library/stdio-binary.factor @@ -26,7 +26,7 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: stdio -USE: arithmetic +USE: math USE: stack USE: streams USE: strings diff --git a/library/strings.factor b/library/strings.factor index 3c946c3a78..63099b9b71 100644 --- a/library/strings.factor +++ b/library/strings.factor @@ -26,11 +26,11 @@ ! 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 -- ? ) diff --git a/library/test/benchmark/empty-loop.factor b/library/test/benchmark/empty-loop.factor index ae7fa233a8..87bf850dd2 100644 --- a/library/test/benchmark/empty-loop.factor +++ b/library/test/benchmark/empty-loop.factor @@ -1,5 +1,5 @@ IN: scratchpad -USE: arithmetic +USE: math USE: test [ 2000000 [ ] times ] time diff --git a/library/test/benchmark/sort.factor b/library/test/benchmark/sort.factor index a6f7dc5b04..ce8daa85dd 100644 --- a/library/test/benchmark/sort.factor +++ b/library/test/benchmark/sort.factor @@ -1,6 +1,6 @@ IN: scratchpad -USE: arithmetic USE: lists +USE: math USE: random USE: stack USE: test diff --git a/library/test/continuations.factor b/library/test/continuations.factor index 3e32995cc1..6159ec0e8e 100644 --- a/library/test/continuations.factor +++ b/library/test/continuations.factor @@ -1,9 +1,9 @@ IN: scratchpad -USE: arithmetic USE: combinators USE: continuations USE: kernel USE: lists +USE: math USE: namespaces USE: stack USE: stdio diff --git a/library/test/hashtables.factor b/library/test/hashtables.factor index c909166947..05d38e1f82 100644 --- a/library/test/hashtables.factor +++ b/library/test/hashtables.factor @@ -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 diff --git a/library/test/io/no-trailing-eol.factor b/library/test/io/no-trailing-eol.factor index 4da8a500b9..8fbf328f59 100644 --- a/library/test/io/no-trailing-eol.factor +++ b/library/test/io/no-trailing-eol.factor @@ -1,2 +1,2 @@ -USE: arithmetic +USE: math 2 2 + \ No newline at end of file diff --git a/library/test/jvm-compiler/auxiliary.factor b/library/test/jvm-compiler/auxiliary.factor index 6356e3dc38..35901fcfb9 100644 --- a/library/test/jvm-compiler/auxiliary.factor +++ b/library/test/jvm-compiler/auxiliary.factor @@ -1,7 +1,7 @@ IN: scratchpad -USE: arithmetic USE: combinators USE: kernel +USE: math USE: stack USE: stdio USE: test diff --git a/library/test/jvm-compiler/compiler-types.factor b/library/test/jvm-compiler/compiler-types.factor index b15fc7b4ea..53206536d7 100644 --- a/library/test/jvm-compiler/compiler-types.factor +++ b/library/test/jvm-compiler/compiler-types.factor @@ -1,5 +1,4 @@ IN: scratchpad -USE: arithmetic USE: combinators USE: compiler USE: kernel diff --git a/library/test/jvm-compiler/compiler.factor b/library/test/jvm-compiler/compiler.factor index d95df6db7e..578a5e3a7c 100644 --- a/library/test/jvm-compiler/compiler.factor +++ b/library/test/jvm-compiler/compiler.factor @@ -1,5 +1,4 @@ IN: scratchpad -USE: arithmetic USE: combinators USE: compiler USE: inspector diff --git a/library/test/jvm-compiler/inference.factor b/library/test/jvm-compiler/inference.factor index 1eb5e583d2..8b022a94b9 100644 --- a/library/test/jvm-compiler/inference.factor +++ b/library/test/jvm-compiler/inference.factor @@ -1,5 +1,4 @@ IN: scratchpad -USE: arithmetic USE: compiler USE: lists USE: math diff --git a/library/test/jvm-compiler/miscellaneous.factor b/library/test/jvm-compiler/miscellaneous.factor index 5db045fc95..0c81c55cf7 100644 --- a/library/test/jvm-compiler/miscellaneous.factor +++ b/library/test/jvm-compiler/miscellaneous.factor @@ -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 diff --git a/library/test/jvm-compiler/tail.factor b/library/test/jvm-compiler/tail.factor index 09034428f8..78a6434884 100644 --- a/library/test/jvm-compiler/tail.factor +++ b/library/test/jvm-compiler/tail.factor @@ -1,8 +1,8 @@ IN: scratchpad -USE: arithmetic USE: combinators USE: kernel USE: lists +USE: math USE: prettyprint USE: stack USE: stdio diff --git a/library/test/jvm-compiler/types.factor b/library/test/jvm-compiler/types.factor index 34366c53c7..d0133b8643 100644 --- a/library/test/jvm-compiler/types.factor +++ b/library/test/jvm-compiler/types.factor @@ -1,7 +1,7 @@ IN: scratchpad -USE: arithmetic USE: compiler USE: lists +USE: math USE: stack USE: stdio USE: strings diff --git a/library/test/lists/assoc.factor b/library/test/lists/assoc.factor index e7d88184d6..26bbc346c7 100644 --- a/library/test/lists/assoc.factor +++ b/library/test/lists/assoc.factor @@ -1,6 +1,6 @@ IN: scratchpad -USE: arithmetic USE: lists +USE: math USE: namespaces USE: test diff --git a/library/test/lists/java.factor b/library/test/lists/java.factor index a991bde64d..6d59a15afe 100644 --- a/library/test/lists/java.factor +++ b/library/test/lists/java.factor @@ -1,6 +1,6 @@ -USE: arithmetic USE: compiler USE: lists +USE: math USE: stack USE: strings USE: test diff --git a/library/test/lists/lists.factor b/library/test/lists/lists.factor index 4f7520f6d9..a6f07b89df 100644 --- a/library/test/lists/lists.factor +++ b/library/test/lists/lists.factor @@ -1,8 +1,8 @@ IN: scratchpad -USE: arithmetic USE: kernel USE: lists USE: logic +USE: math USE: namespaces USE: stack USE: test diff --git a/library/test/math/bignum.factor b/library/test/math/bignum.factor index 124653e8c0..1e17337b8e 100644 --- a/library/test/math/bignum.factor +++ b/library/test/math/bignum.factor @@ -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 diff --git a/library/test/math/bitops.factor b/library/test/math/bitops.factor index 34227ec2c0..4e09e60e5f 100644 --- a/library/test/math/bitops.factor +++ b/library/test/math/bitops.factor @@ -1,6 +1,6 @@ IN: scratchpad -USE: arithmetic USE: kernel +USE: math USE: stack USE: test diff --git a/library/test/math/complex.factor b/library/test/math/complex.factor index 7b1f7bdfa1..0565bff62d 100644 --- a/library/test/math/complex.factor +++ b/library/test/math/complex.factor @@ -1,6 +1,6 @@ IN: scratchpad -USE: arithmetic USE: kernel +USE: math USE: stack USE: test diff --git a/library/test/math/float.factor b/library/test/math/float.factor index 6830e1306d..c45e4f458c 100644 --- a/library/test/math/float.factor +++ b/library/test/math/float.factor @@ -1,6 +1,6 @@ IN: scratchpad -USE: arithmetic USE: kernel +USE: math USE: stack USE: test diff --git a/library/test/math/gcd.factor b/library/test/math/gcd.factor index fd738e69fb..be81e048b1 100644 --- a/library/test/math/gcd.factor +++ b/library/test/math/gcd.factor @@ -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 diff --git a/library/test/math/irrational.factor b/library/test/math/irrational.factor index 1b7c55c420..2af5a62b50 100644 --- a/library/test/math/irrational.factor +++ b/library/test/math/irrational.factor @@ -1,5 +1,4 @@ IN: scratchpad -USE: arithmetic USE: kernel USE: math USE: test diff --git a/library/test/math/rational.factor b/library/test/math/rational.factor index b9228d7c34..502564add6 100644 --- a/library/test/math/rational.factor +++ b/library/test/math/rational.factor @@ -1,6 +1,6 @@ IN: scratchpad -USE: arithmetic USE: kernel +USE: math USE: stack USE: test USE: unparser diff --git a/library/test/math/simpson.factor b/library/test/math/simpson.factor index d0bfc1cf81..4c1b63ef14 100644 --- a/library/test/math/simpson.factor +++ b/library/test/math/simpson.factor @@ -1,5 +1,4 @@ IN: scratchpad -USE: arithmetic USE: math USE: test diff --git a/library/test/namespaces/java.factor b/library/test/namespaces/java.factor index 0b99922330..8a73e051f7 100644 --- a/library/test/namespaces/java.factor +++ b/library/test/namespaces/java.factor @@ -1,7 +1,7 @@ IN: scratchpad -USE: arithmetic USE: compiler USE: kernel +USE: math USE: namespaces USE: stack USE: test diff --git a/library/test/parse-number.factor b/library/test/parse-number.factor index 810b126a9c..3efbf9ac36 100644 --- a/library/test/parse-number.factor +++ b/library/test/parse-number.factor @@ -1,5 +1,5 @@ IN: scratchpad -USE: arithmetic +USE: math USE: parser USE: strings USE: test diff --git a/library/test/random.factor b/library/test/random.factor index 666fdea9be..2373f05df5 100644 --- a/library/test/random.factor +++ b/library/test/random.factor @@ -1,8 +1,8 @@ IN: scratchpad -USE: arithmetic USE: kernel USE: lists USE: logic +USE: math USE: namespaces USE: random USE: stack diff --git a/library/test/strings.factor b/library/test/strings.factor index 86084eae6e..e564822a03 100644 --- a/library/test/strings.factor +++ b/library/test/strings.factor @@ -1,7 +1,7 @@ IN: scratchpad -USE: arithmetic USE: combinators USE: kernel +USE: math USE: namespaces USE: stack USE: strings diff --git a/library/test/test.factor b/library/test/test.factor index b250cea605..d1584e1584 100644 --- a/library/test/test.factor +++ b/library/test/test.factor @@ -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 ; diff --git a/library/test/vectors.factor b/library/test/vectors.factor index be0e7e39fb..33098e517d 100644 --- a/library/test/vectors.factor +++ b/library/test/vectors.factor @@ -1,6 +1,6 @@ -USE: arithmetic USE: lists USE: kernel +USE: math USE: random USE: stack USE: test diff --git a/library/test/words.factor b/library/test/words.factor index 48e62cebbc..3332f175d0 100644 --- a/library/test/words.factor +++ b/library/test/words.factor @@ -1,5 +1,5 @@ IN: scratchpad -USE: arithmetic +USE: math USE: test USE: words diff --git a/library/vector-combinators.factor b/library/vector-combinators.factor index 68e79c2446..ef6e023e7d 100644 --- a/library/vector-combinators.factor +++ b/library/vector-combinators.factor @@ -26,10 +26,10 @@ ! 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 -- ) diff --git a/library/vectors.factor b/library/vectors.factor index 058a3c7d79..516ba187b1 100644 --- a/library/vectors.factor +++ b/library/vectors.factor @@ -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 ) diff --git a/native/arithmetic.c b/native/arithmetic.c index 8a724db56b..b52664e90d 100644 --- a/native/arithmetic.c +++ b/native/arithmetic.c @@ -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) diff --git a/native/arithmetic.h b/native/arithmetic.h index 841ce90f6f..78cf557ccd 100644 --- a/native/arithmetic.h +++ b/native/arithmetic.h @@ -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) \ diff --git a/native/factor.h b/native/factor.h index 7d9099021f..be30f7c8dc 100644 --- a/native/factor.h +++ b/native/factor.h @@ -25,11 +25,11 @@ /* 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) diff --git a/native/fixnum.c b/native/fixnum.c index cfd7545dd5..02df81396b 100644 --- a/native/fixnum.c +++ b/native/fixnum.c @@ -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 diff --git a/native/io.h b/native/io.h index 089e63ff60..31a792131d 100644 --- a/native/io.h +++ b/native/io.h @@ -1,3 +1,5 @@ +FILE* debug_fd; + typedef enum { IO_TASK_READ_LINE, IO_TASK_READ_COUNT, diff --git a/native/memory.c b/native/memory.c index d699a28a91..d57507a9dc 100644 --- a/native/memory.c +++ b/native/memory.c @@ -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); } diff --git a/native/primitives.c b/native/primitives.c index 63f3cc4100..f2fadc14bc 100644 --- a/native/primitives.c +++ b/native/primitives.c @@ -73,7 +73,6 @@ XT primitives[] = { primitive_lesseq, primitive_greater, primitive_greatereq, - primitive_gcd, primitive_facos, primitive_fasin, primitive_fatan, diff --git a/native/primitives.h b/native/primitives.h index 9990a9d11e..baeaa8997b 100644 --- a/native/primitives.h +++ b/native/primitives.h @@ -1,4 +1,4 @@ extern XT primitives[]; -#define PRIMITIVE_COUNT 141 +#define PRIMITIVE_COUNT 140 CELL primitive_to_xt(CELL primitive);