]> gitweb.factorcode.org Git - factor.git/commitdiff
decimals: change pprint* to not use formatting.private:format-decimal.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 18 Mar 2021 20:03:43 +0000 (13:03 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 18 Mar 2021 20:03:43 +0000 (13:03 -0700)
extra/decimals/decimals.factor

index cb33fb4e2c9c5229f8eefbc2e12fdfe33cd9cd84..eaa9d408e539906411a2b2024f25881d3cc02679 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators.short-circuit formatting.private
-kernel lexer locals math math.functions math.order math.parser
-prettyprint.backend prettyprint.custom prettyprint.sections
-sequences splitting ;
+USING: accessors combinators.short-circuit kernel lexer math
+math.functions math.order math.parser prettyprint.backend
+prettyprint.custom prettyprint.sections sequences splitting
+strings ;
 IN: decimals
 
 TUPLE: decimal { mantissa read-only } { exponent read-only } ;
@@ -86,5 +86,15 @@ M: decimal <=>
 
 M: decimal pprint*
     \ DECIMAL: [
-        >decimal< [ 10^ * ] [ abs format-decimal ] bi text
+        [ mantissa>> abs number>string ]
+        [
+            exponent>> dup 0 > [ CHAR: 0 <string> append ] [
+                dup 0 < [
+                    abs
+                    [ CHAR: 0 pad-head ] [ cut-slice* ] bi
+                    over empty? [ nip "0." prepend ] [ "." glue ] if
+                ] [ drop ] if
+            ] if
+        ]
+        [ mantissa>> 0 < [ "-" prepend ] when ] tri text
     ] pprint-prefix ;