]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: some fixes by @jonenst.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 25 Feb 2021 23:32:59 +0000 (17:32 -0600)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 25 Feb 2021 23:32:59 +0000 (17:32 -0600)
basis/prettyprint/backend/backend.factor
basis/prettyprint/prettyprint-tests.factor
core/math/parser/parser-tests.factor
core/syntax/syntax-docs.factor

index 4bf3938485160591649e77bc8ac7c54fa523a5b9..fba8307787199590fc16de360d4e09be0e46b912 100644 (file)
@@ -2,11 +2,12 @@
 ! 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
 
@@ -82,7 +83,7 @@ M: real pprint*
     } 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? [
index 272360c6bf4104f8e7724f8a93051db26cd57eea..6e7d7acb50ba50adf725afc089ea4096885de273 100644 (file)
@@ -19,6 +19,10 @@ IN: prettyprint.tests
 { "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
 
index cbfaba28bab91595628e3f372c2e7fbf679829c6..9022fc7f59c76cfdc87fbd4260474f961a5da954 100644 (file)
@@ -200,11 +200,19 @@ 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
 
index 6788acf7b59a7dd2e383f0429e7bcdbe01005d29..381ad2e1aaa2061cb95ba60e47d1fe1371986bb3 100644 (file)
@@ -111,10 +111,16 @@ ARTICLE: "syntax-floats" "Float syntax"
 { $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 = ."