! 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 } [
{ 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
! 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 } ;
M: decimal <=>
2dup before? [ 2drop +lt+ ] [ equal? +eq+ +gt+ ? ] if ; inline
+
+M: decimal pprint*
+ \ DECIMAL: [
+ >decimal< [ 10^ * ] [ abs format-decimal ] bi text
+ ] pprint-prefix ;