]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: rename some private words
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 12 Feb 2024 02:50:26 +0000 (18:50 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 12 Feb 2024 02:50:26 +0000 (18:50 -0800)
basis/calendar/format/format.factor
basis/formatting/formatting.factor
core/math/parser/parser-tests.factor
core/math/parser/parser.factor

index 843c26f4fd10c544e871dadf31edc95bf2b587bd..b2f6ee388eb694ef5b0473b77f536229cbac997d 100644 (file)
@@ -32,7 +32,7 @@ MACRO: formatted ( spec -- quot )
 ! Should be enough for anyone, allows to not do a fancy
 ! algorithm to detect infinite decimals (e.g 1/3)
 : ss.SSSSSS ( timestamp -- )
-    second>> >float "0" 9 6 "f" "C" format-float* write ;
+    second>> >float "0" 9 6 "f" "C" format-float write ;
 
 : hhmm ( timestamp -- ) [ hh ] [ mm ] bi ;
 
index a04583367d100f2706ba7c76044fce0049f49c12..723783fee635fc99bfe717ff2dc1a8e560228d42 100644 (file)
@@ -5,7 +5,7 @@ calendar.private combinators combinators.smart generalizations
 io io.streams.string kernel math math.functions math.parser
 multiline namespaces peg.ebnf present prettyprint quotations
 sequences sequences.generalizations splitting strings unicode ;
-FROM: math.parser.private => format-float* ;
+FROM: math.parser.private => format-float ;
 IN: formatting
 
 ERROR: unknown-format-directive value ;
@@ -57,7 +57,7 @@ ERROR: unknown-format-directive value ;
     ] keepd neg? [ CHAR: - prefix ] when ;
 
 : format-float-fast ( x digits string -- string )
-    [ "" -1 ] 2dip "C" format-float* ;
+    [ "" -1 ] 2dip "C" format-float ;
 
 : format-fast-scientific? ( x digits -- x' digits ? )
     over float? [ t ]
index b0eff91870266281d0b1b79c73086dcb13c14c88..f7c86804c6be5202469ef7dc1244cbbdcb8799a4 100644 (file)
@@ -495,7 +495,7 @@ unit-test
 
 ! Missing locale
 { "" } [
-    33.4 "" 4 4 "f" "missing" format-float*
+    33.4 "" 4 4 "f" "missing" format-float
 ] unit-test
 
 ! Literal byte arrays are mutable, so (format-float) isn't foldable.
@@ -654,7 +654,7 @@ unit-test
     {                1e23                "1e23"  }
 } [| tuple |
     tuple first2 :> ( n str )
-    { str } [ n format-float ] unit-test
+    { str } [ n float>dec ] unit-test
 ] each
 
 {
@@ -720,7 +720,7 @@ unit-test
        6.447847606411378e49
        5.465125341473931e80
 } [| n |
-    { n } [ n format-float dec> ] unit-test
+    { n } [ n float>dec dec> ] unit-test
 ] each
 
 {
@@ -739,6 +739,6 @@ unit-test
     0x455FCEB5B44D932F
     0x45B5C534DA985042
 } [| n |
-    { n } [ n bits>double format-float dec> double>bits ]
+    { n } [ n bits>double float>dec dec> double>bits ]
     unit-test
 ] each
index 22abda451473f6be625e1d0807ce3fda773593d0..e1754e4e07d8d430f91d8a806f72a9a86866ba46 100644 (file)
@@ -7,6 +7,16 @@ IN: math.parser
 
 <PRIVATE
 PRIMITIVE: (format-float) ( n fill width precision format locale -- byte-array )
+
+: format-string ( format -- format )
+    0 suffix >byte-array ; foldable
+
+! Used as primitive for formatting vocabulary
+: format-float ( n fill width precision format locale -- string )
+    [ format-string ] 4dip
+    [ format-string ] bi@
+    (format-float) >string ; inline
+
 PRIVATE>
 
 : digit> ( ch -- n )
@@ -413,30 +423,30 @@ CONSTANT: ONES B{
     48 49 50 51 52 53 54 55 56 57 48 49 50 51 52 53 54 55 56 57
 }
 
-: (two-digit) ( num accum -- num' accum )
+: two-digit ( num accum -- num' accum )
     [
         100 /mod [ TENS nth-unsafe ] [ ONES nth-unsafe ] bi
     ] dip [ push ] keep [ push ] keep ; inline
 
-: (one-digit) ( num accum -- num' accum )
+: one-digit ( num accum -- num' accum )
     [ 10 /mod CHAR: 0 + ] dip [ push ] keep ; inline
 
-: (bignum>dec) ( num accum -- num' accum )
+: bignum>dec ( num accum -- num' accum )
     [ over most-positive-fixnum > ]
-    [ { bignum sbuf } declare (two-digit) ] while
+    [ { bignum sbuf } declare two-digit ] while
     [ >fixnum ] dip ; inline
 
-: (fixnum>dec) ( num accum -- num' accum )
+: fixnum>dec ( num accum -- num' accum )
     { fixnum sbuf } declare
-    [ over 10 >= ] [ (two-digit) ] while
-    [ over zero? ] [ (one-digit) ] until ; inline
+    [ over 10 >= ] [ two-digit ] while
+    [ over zero? ] [ one-digit ] until ; inline
 
-GENERIC: (positive>dec) ( num -- str )
+GENERIC: positive>dec ( num -- str )
 
-M: bignum (positive>dec)
-    12 <sbuf> (bignum>dec) (fixnum>dec) "" like reverse! nip ; inline
+M: bignum positive>dec
+    12 <sbuf> bignum>dec fixnum>dec "" like reverse! nip ; inline
 
-: (count-digits) ( digits n -- digits' )
+: count-digits ( digits n -- digits' )
     {
         { [ dup 10 < ] [ drop ] }
         { [ dup 100 < ] [ drop 1 fixnum+fast ] }
@@ -462,33 +472,34 @@ M: bignum (positive>dec)
                 ] if fixnum+fast
             ] [
                 [ 12 fixnum+fast ] [ 1,000,000,000,000 /i ] bi*
-                (count-digits)
+                count-digits
             ] if
         ]
     } cond ; inline recursive
 
-M: fixnum (positive>dec)
-    1 over (count-digits) <sbuf> (fixnum>dec) "" like reverse! nip ; inline
-
-: (positive>base) ( num radix -- str )
-    dup 1 <= [ invalid-radix ] when
-    [ dup 0 > ] swap [ /mod >digit ] curry "" produce-as nip
-    reverse! ; inline
+M: fixnum positive>dec
+    1 over count-digits <sbuf> fixnum>dec "" like reverse! nip ; inline
 
 : positive>base ( num radix -- str )
-    dup 10 = [ drop (positive>dec) ] [ (positive>base) ] if ; inline
+    {
+        { 10 [ positive>dec ] }
+        [
+            dup 1 <= [ invalid-radix ] when
+            [ dup 0 > ] swap [ /mod >digit ] curry "" produce-as nip
+            reverse!
+        ]
+    } case ;
 
 PRIVATE>
 
 GENERIC#: >base 1 ( n radix -- str )
 
-: number>string ( n -- str ) 10 >base ; inline
-
 : >bin ( n -- str ) 2 >base ; inline
 : >oct ( n -- str ) 8 >base ; inline
+: >dec ( n -- str ) 10 >base ; inline
 : >hex ( n -- str ) 16 >base ; inline
 
-ALIAS: >dec number>string
+ALIAS: number>string >dec
 
 M: integer >base
     {
@@ -550,14 +561,6 @@ M: ratio >base
         [ invalid-radix ]
     } case ;
 
-: format-string ( format -- format )
-    0 suffix >byte-array ; foldable
-
-: format-float* ( n fill width precision format locale -- string )
-    [ format-string ] 4dip
-    [ format-string ] bi@
-    (format-float) >string ; inline
-
 ! Dragonbox algorithm
 
 : ⌊nlog10_2⌋ ( n -- m ) 315653 * -20 shift ; inline
@@ -993,12 +996,12 @@ CONSTANT: lookup-table {
     2over swap [ + ] [ neg ] bi [ 1 max ] bi@ + 17 >
     [ exponential-format ] [ decimal-format ] if ; inline
 
-: format-float ( n -- str )
+: float>dec ( n -- str )
     >double< dragonbox general-format ; inline
 
 : float>base ( n radix -- str )
     {
-        { 10 [ format-float ] }
+        { 10 [ float>dec ] }
         [ bin-float>base ]
     } case ; inline