]> gitweb.factorcode.org Git - factor.git/commitdiff
fix math.parser's ?neg for nans
authorJon Harper <jon.harper87@gmail.com>
Sun, 17 Jul 2016 18:13:36 +0000 (20:13 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 25 Feb 2021 23:11:04 +0000 (17:11 -0600)
core/math/parser/parser.factor

index 9646401a667bbc8c2f214239fd8ed2c51f1eb34e..01bf05793e417b775797859f0982a325d0f82933 100644 (file)
@@ -168,12 +168,19 @@ CONSTANT: min-magnitude-2 -1074
         [ make-float-bin-exponent ]
     } cond ;
 
+: bignum-?neg ( n -- -n )
+    dup first-bignum bignum= [ drop most-negative-fixnum ] [ neg ] if ;
+
+: fp-?neg ( n -- -n )
+    double>bits 63 2^ bitxor bits>double ;
+
 : ?neg ( n/f -- -n/f )
     [
-        dup bignum? [
-            dup first-bignum bignum=
-            [ drop most-negative-fixnum ] [ neg ] if
-        ] [ neg ] if
+        {
+            { [ dup bignum? ] [ bignum-?neg ] }
+            { [ dup fp-nan? ] [ fp-?neg ] }
+            [ neg ]
+        } cond
     ] [ f ] if* ; inline
 
 : add-ratio? ( n/f -- ? )