From 49573c5952013bcee0b8784c127af7217c10f329 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 18 Mar 2021 12:47:37 -0700 Subject: [PATCH] decimals: adding prettyprint. --- extra/decimals/decimals-tests.factor | 13 +++++++++++-- extra/decimals/decimals.factor | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/extra/decimals/decimals-tests.factor b/extra/decimals/decimals-tests.factor index 4a9baced07..ce415d87cb 100644 --- a/extra/decimals/decimals-tests.factor +++ b/extra/decimals/decimals-tests.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: continuations decimals grouping kernel kernel.private literals -locals math math.functions math.order random tools.test ; +USING: continuations decimals grouping kernel kernel.private +literals locals math math.functions math.order prettyprint +random tools.test ; IN: decimals.tests { t } [ @@ -49,3 +50,11 @@ ERROR: decimal-test-failure D1 D2 quot ; { f } [ DECIMAL: -2 DECIMAL: -2 before? ] unit-test { t } [ DECIMAL: -3 DECIMAL: -2 before? ] unit-test { t } [ DECIMAL: .5 DECIMAL: 0 DECIMAL: 1.0 between? ] unit-test + +{ "DECIMAL: 0" } [ DECIMAL: 0 unparse ] unit-test +{ "DECIMAL: 0.1" } [ DECIMAL: 0.1 unparse ] unit-test +{ "DECIMAL: 1" } [ DECIMAL: 1.0 unparse ] unit-test +{ "DECIMAL: 1.01" } [ DECIMAL: 1.01 unparse ] unit-test +{ "DECIMAL: -0.1" } [ DECIMAL: -0.1 unparse ] unit-test +{ "DECIMAL: -1" } [ DECIMAL: -1.0 unparse ] unit-test +{ "DECIMAL: -1.01" } [ DECIMAL: -1.01 unparse ] unit-test diff --git a/extra/decimals/decimals.factor b/extra/decimals/decimals.factor index d371a5932a..cb33fb4e2c 100644 --- a/extra/decimals/decimals.factor +++ b/extra/decimals/decimals.factor @@ -1,7 +1,9 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors combinators.short-circuit kernel lexer locals -math math.functions math.order math.parser sequences splitting ; +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 ; IN: decimals TUPLE: decimal { mantissa read-only } { exponent read-only } ; @@ -81,3 +83,8 @@ M: decimal before? M: decimal <=> 2dup before? [ 2drop +lt+ ] [ equal? +eq+ +gt+ ? ] if ; inline + +M: decimal pprint* + \ DECIMAL: [ + >decimal< [ 10^ * ] [ abs format-decimal ] bi text + ] pprint-prefix ; -- 2.34.1