]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: slightly faster ((pow)).
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 12 Jun 2015 03:00:53 +0000 (20:00 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 12 Jun 2015 03:04:44 +0000 (20:04 -0700)
core/math/parser/parser.factor

index da157e9386d277560116fe0fafa24e10aa6b6063..a8b13b9a4157e1c46ebdc0a983f8999398e18551 100644 (file)
@@ -58,9 +58,14 @@ TUPLE: float-parse
     [ store-exponent ] [ drop f ] if* ; inline
 
 : ((pow)) ( base x -- base^x )
-    iota 1 rot [ nip * ] curry reduce ; inline
+    [ 1 ] 2dip
+    [ dup zero? ] [
+        dup odd? [ [ [ * ] keep ] [ 1 - ] bi* ] when
+        [ sq ] [ 2/ ] bi*
+    ] until 2drop ; inline
 
 : (pow) ( base x -- base^x )
+    integer>fixnum-strict
     dup 0 >= [ ((pow)) ] [ [ recip ] [ neg ] bi* ((pow)) ] if ; inline
 
 : add-mantissa-digit ( float-parse i number-parse n digit quot -- float-parse' n/f )