]> gitweb.factorcode.org Git - factor.git/commitdiff
math: faster definition of 2/ (allows inlining of fixnum-shift-fast).
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 11 Sep 2012 00:20:31 +0000 (17:20 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 11 Sep 2012 00:20:31 +0000 (17:20 -0700)
core/math/math.factor

index 20593bd48a89e1db518b1e3acf91e687f84adc9c..983eb826b37128f760952f87fde7048f33d5d1ce 100644 (file)
@@ -66,7 +66,13 @@ ERROR: log2-expects-positive x ;
     dup 0 <= [ log2-expects-positive ] [ (log2) ] if ; inline
 
 : zero? ( x -- ? ) 0 number= ; inline
-: 2/ ( x -- y ) -1 shift ; inline
+
+! the following lines are necessary because the "-1 shift"
+! definition doesn't (yet) compile as nicely...
+GENERIC: 2/ ( x -- y ) foldable
+M: bignum 2/ -1 bignum-shift ; inline
+M: fixnum 2/ -1 fixnum-shift ; inline
+
 : sq ( x -- y ) dup * ; inline
 : neg ( x -- -x ) -1 * ; inline
 : sgn ( x -- n ) dup 0 < [ drop -1 ] [ 0 > 1 0 ? ] if ; inline