! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs byte-arrays byte-vectors classes
classes.algebra.private classes.maybe classes.private
-classes.tuple combinators continuations effects generic
-hash-sets hashtables io.pathnames io.styles kernel lists make
-math math.order math.parser namespaces prettyprint.config
-prettyprint.custom prettyprint.sections prettyprint.stylesheet
-quotations sbufs sequences strings vectors words ;
+classes.tuple combinators combinators.short-circuit
+continuations effects generic hash-sets hashtables io.pathnames
+io.styles kernel lists make math math.order math.parser
+namespaces prettyprint.config prettyprint.custom
+prettyprint.sections prettyprint.stylesheet quotations sbufs
+sequences strings vectors words ;
QUALIFIED: sets
IN: prettyprint.backend
} case ;
: payload-nan? ( f -- ? )
- dup fp-nan? [ fp-nan-payload 0x8000000000000 = not ] [ drop f ] if ;
+ { [ fp-nan? ] [ 0/0. fp-bitwise= not ] [ -0/0. fp-bitwise= not ] } 1&& ;
M: float pprint*
dup payload-nan? [
{ "0o1.1p4" } [ 8 number-base [ 18.0 unparse ] with-variable ] unit-test
{ "0x1.2p4" } [ 16 number-base [ 18.0 unparse ] with-variable ] unit-test
{ "1267650600228229401496703205376" } [ 1 100 shift unparse ] unit-test
+{ "1/0." } [ 1/0. unparse ] unit-test
+{ "-1/0." } [ -1/0. unparse ] unit-test
+{ "0/0." } [ 0/0. unparse ] unit-test
+{ "-0/0." } [ -0/0. unparse ] unit-test
{ "+" } [ \ + unparse ] unit-test
{ "0/0." } [ 0.0 0.0 / number>string ] unit-test
+{ "0/0." } [ 0.0 0.0 / ?pos number>string ] unit-test
+{ "-0/0." } [ 0.0 0.0 / ?neg number>string ] unit-test
+
+{ t } [ "0/0." string>number fp-nan? ] unit-test
+{ t } [ "-0/0." string>number fp-nan? ] unit-test
+
+{ f } [ "0/0." string>number fp-sign ] unit-test
+{ t } [ "-0/0." string>number fp-sign ] unit-test
+
{ "1/0." } [ 1.0 0.0 / number>string ] unit-test
{ "-1/0." } [ -1.0 0.0 / number>string ] unit-test
-{ t } [ "0/0." string>number fp-nan? ] unit-test
{ 1/0. } [ "1/0." string>number ] unit-test
{ $table
{ "Positive infinity" { $snippet "1/0." } }
{ "Negative infinity" { $snippet "-1/0." } }
-{ "Not-a-number" { $snippet "0/0." } }
+{ "Not-a-number (positive)" { $snippet "0/0." } }
+{ "Not-a-number (negative)" { $snippet "-0/0." } }
}
"A Not-a-number literal with an arbitrary payload can also be input:"
{ $subsections POSTPONE: NAN: }
+"To see the 64 bit value of " { $snippet "0/0." } " on your platform, execute the following code :"
+{ $code
+ "USING: io math math.parser ;"
+ "\"NAN: \" write 0/0. double>bits >hex print"
+}
"Hexadecimal, octal and binary float literals are also supported. These consist of a hexadecimal, octal or binary literal with a decimal point and a mandatory base-two exponent expressed as a decimal number after " { $snippet "p" } " or " { $snippet "P" } ":"
{ $example
"8.0 0x1.0p3 = ."