]> gitweb.factorcode.org Git - factor.git/commitdiff
add 10^ to math.functions and update usages
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 11 Aug 2009 23:00:24 +0000 (18:00 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 11 Aug 2009 23:00:24 +0000 (18:00 -0500)
14 files changed:
basis/calendar/format/format.factor
basis/formatting/formatting.factor
basis/io/files/info/windows/windows.factor
basis/math/functions/functions.factor
extra/math/analysis/analysis.factor
extra/math/text/english/english.factor
extra/math/text/french/french.factor
extra/math/text/utils/utils-docs.factor [changed mode: 0644->0755]
extra/math/text/utils/utils-tests.factor [changed mode: 0644->0755]
extra/math/text/utils/utils.factor [changed mode: 0644->0755]
extra/money/money.factor
extra/project-euler/048/048.factor
extra/project-euler/ave-time/ave-time.factor
extra/svg/svg.factor

index ad43cc2f1d6d17fd811c14c4fbfce6aa641f9e55..a187f0c9af75abb42270d4adcb6ef077c2519780 100644 (file)
@@ -162,7 +162,7 @@ M: timestamp year. ( timestamp -- )
 \r
 : read-rfc3339-seconds ( s -- s' ch )\r
     "+-Z" read-until [\r
-        [ string>number ] [ length 10 swap ^ ] bi / +\r
+        [ string>number ] [ length 10^ ] bi / +\r
     ] dip ;\r
 \r
 : (rfc3339>timestamp) ( -- timestamp )\r
index f8b9ba501ba68e5c953bb0e5f7aa2f855269f2bb..55ebdf1442d6073c73984c767c6a69dfec241947 100644 (file)
@@ -32,7 +32,7 @@ IN: formatting
     [ "." split1 ] dip [ CHAR: 0 pad-tail ] [ head-slice ] bi "." glue ;
 
 : max-digits ( n digits -- n' )
-    10 swap ^ [ * round ] keep / ; inline
+    10^ [ * round ] keep / ; inline
 
 : >exp ( x -- exp base )
     [ 
index 81e43f8dd9cd0dd5d2655b7a34f56e926c30e770..88e1547b7b2bbc2c5ab0ad89a6994a4cecd5108e 100755 (executable)
@@ -9,11 +9,11 @@ calendar ascii combinators.short-circuit locals ;
 IN: io.files.info.windows
 
 :: round-up-to ( n multiple -- n' )
-    n multiple rem dup 0 = [
-        drop n
+    n multiple rem [
+        n
     ] [
         multiple swap - n +
-    ] if ;
+    ] if-zero ;
 
 TUPLE: windows-file-info < file-info attributes ;
 
index 314062591d192cff360e643d1f7479393e937268..3cbe8e19d4016d277e4bab3259d4863f4b507519 100644 (file)
@@ -104,10 +104,12 @@ PRIVATE>
 : divisor? ( m n -- ? )
     mod 0 = ;
 
+ERROR: non-trivial-divisor n ;
+
 : mod-inv ( x n -- y )
     [ nip ] [ gcd 1 = ] 2bi
     [ dup 0 < [ + ] [ nip ] if ]
-    [ "Non-trivial divisor found" throw ] if ; foldable
+    [ non-trivial-divisor ] if ; foldable
 
 : ^mod ( x y n -- z )
     over 0 < [
@@ -116,6 +118,8 @@ PRIVATE>
         -rot (^mod)
     ] if ; foldable
 
+: 10^ ( n -- n' ) 10 swap ^ ; inline
+
 GENERIC: absq ( x -- y ) foldable
 
 M: real absq sq ;
index a1fc0bd07b904c0301e533bfa74e6e993fa0e652..16a45fc691fce9400b5b44387391475aa5fc264b 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman, Slava Pestov, Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators.short-circuit kernel math math.constants math.functions
-    math.vectors sequences ;
+USING: combinators.short-circuit kernel math math.constants
+math.functions math.vectors sequences ;
 IN: math.analysis
 
 <PRIVATE
index 492453450b9ecf0f6e0433999741d4ad1b745c34..422036d5cc39ae6c44c819f5632c926439653c17 100755 (executable)
@@ -87,7 +87,7 @@ SYMBOL: and-needed?
     ] if ;
 
 : (number>text) ( n -- str )
-    [ negative-text ] [ abs 3digit-groups recombine ] bi append ;
+    [ negative-text ] [ abs 3 digit-groups recombine ] bi append ;
 
 PRIVATE>
 
index f8b97103eb30183f635a95160c49a360e505851e..46e326b7e77184929e3d7cc1bab8146e9b9fb2a4 100644 (file)
@@ -73,7 +73,7 @@ MEMO: units ( -- seq ) ! up to 10^99
     } cond ;
 
 : over-1000000 ( n -- str )
-    3digit-groups [ 1+ units nth n-units ] map-index sift
+    3 digit-groups [ 1+ units nth n-units ] map-index sift
     reverse " " join ;
 
 : decompose ( n -- str ) 1000000 /mod [ over-1000000 ] dip complete ;
old mode 100644 (file)
new mode 100755 (executable)
index e1d1a00..2352ab9
@@ -1,6 +1,6 @@
 USING: help.markup help.syntax ;
 IN: math.text.utils
 
-HELP: 3digit-groups
-{ $values { "n" "a positive integer" } { "seq" "a sequence" } }
-{ $description "Decompose a number into 3 digits groups and return them in a sequence, starting with the units, then the tenths, etc." } ;
+HELP: digit-groups
+{ $values { "n" "a positive integer" } { "k" "a positive integer" } { "seq" "a sequence" } }
+{ $description "Decompose a number into groups of " { $snippet "k" } " digits and return them in a sequence starting with the least significant grouped digits first." } ;
old mode 100644 (file)
new mode 100755 (executable)
index d14bb06..04fbcdc
@@ -1,3 +1,3 @@
 USING: math.text.utils tools.test ;
 
-[ { 1 999 2 } ] [ 2999001 3digit-groups ] unit-test
+[ { 1 999 2 } ] [ 2999001 3 digit-groups ] unit-test
old mode 100644 (file)
new mode 100755 (executable)
index 422a79a..13551f1
@@ -1,7 +1,7 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math sequences ;
+USING: kernel fry math.functions math sequences ;
 IN: math.text.utils
 
-: 3digit-groups ( n -- seq )
-    [ dup 0 > ] [ 1000 /mod ] produce nip ;
+: digit-groups ( n k -- seq )
+    [ dup 0 > ] swap '[ _ 10^ /mod ] produce nip ;
index 994d2143355c5925e2c583b855625ac325215d14..36dedb2a653b92e2f661317f227a2a1256ce23f0 100644 (file)
@@ -28,6 +28,6 @@ ERROR: not-an-integer x ;
     [
         [ dup string>number [ nip ] [ not-an-integer ] if* ] bi@
     ] keep length
-    10 swap ^ / + swap [ neg ] when ;
+    10^ / + swap [ neg ] when ;
 
 SYNTAX: DECIMAL: scan parse-decimal parsed ;
index 640a3a68f69efe0549e752388b9dc10bf259e493..fde3fa6026af4a0adbfad6d9e50c53025d9b69e0 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.ranges project-euler.common sequences ;
+USING: kernel math math.functions math.ranges
+project-euler.common sequences ;
 IN: project-euler.048
 
 ! http://projecteuler.net/index.php?section=problems&id=48
@@ -17,7 +18,7 @@ IN: project-euler.048
 ! --------
 
 : euler048 ( -- answer )
-    1000 [1,b] [ dup ^ ] sigma 10 10 ^ mod ;
+    1000 [1,b] [ dup ^ ] sigma 10 10^ mod ;
 
 ! [ euler048 ] 100 ave-time
 ! 276 ms run / 1 ms GC ave time - 100 trials
index a7762836f19bbe23b00d1e53607d70d2bac89b44..6c555f92b570e832bedc103fe3d7727d87dc89e0 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: continuations fry io kernel make math math.functions math.parser
-    math.statistics memory tools.time ;
+USING: continuations fry io kernel make math math.functions
+math.parser math.statistics memory tools.time ;
 IN: project-euler.ave-time
 
 : nth-place ( x n -- y )
-    10 swap ^ [ * round >integer ] keep /f ;
+    10^ [ * round >integer ] keep /f ;
 
 : collect-benchmarks ( quot n -- seq )
     [
index 2ed5d21707a84c0f1ec3aadaed21216686e38d06..2d2d38314ab6e2f2ac119dba67a753c9c24f2a93 100644 (file)
@@ -11,7 +11,7 @@ XML-NS: inkscape-name http://www.inkscape.org/namespaces/inkscape
 
 : svg-string>number ( string -- number )
     { { CHAR: E CHAR: e } } substitute "e" split1
-    [ string>number ] [ [ string>number 10 swap ^ ] [ 1 ] if* ] bi* *
+    [ string>number ] [ [ string>number 10^ ] [ 1 ] if* ] bi* *
     >float ;
 
 : degrees ( deg -- rad ) pi * 180.0 / ;