]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: add tests/docs for floats 0b 0x bin> float> since they work
authorJon Harper <jon.harper87@gmail.com>
Tue, 23 Jun 2015 22:00:25 +0000 (00:00 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 30 Jul 2015 18:04:51 +0000 (11:04 -0700)
core/math/parser/parser-tests.factor
core/syntax/syntax-docs.factor

index 88d8168e4a6d67f59ecd4f7cef094b21993fd1a4..1145346d92a3ae2ef4fb9fabaca447e56b1c5def 100644 (file)
@@ -99,6 +99,8 @@ unit-test
 
 { 0x1.999999999999ap-3 } [ "0.2" string>number ] unit-test
 { 0x1.3333333333333p0  } [ "1.2" string>number ] unit-test
+{ 0o1.146314631463146314p0 } [ "1.2" string>number ] unit-test
+{ 0b1.0011001100110011001100110011001100110011001100110011p0 } [ "1.2" string>number ] unit-test
 { 0x1.5555555555555p0  } [ "1.333,333,333,333,333,333" string>number ] unit-test
 { 0x1.aaaaaaaaaaaabp0  } [ "1.666,666,666,666,666,666" string>number ] unit-test
 
@@ -241,6 +243,40 @@ unit-test
 { 1/0. } [ "1.0p1024" hex> ] unit-test
 { -1/0. } [ "-1.0p1024" hex> ] unit-test
 
+{ 1.0 } [ "1.0p0" bin> ] unit-test
+{ 1.5 } [ "1.1p0" bin> ] unit-test
+{ 1.875 } [ "1.111p0" bin> ] unit-test
+{ 1.90625 } [ "1.11101p0" bin> ] unit-test
+{ 1.03125 } [ "1.00001p0" bin> ] unit-test
+{ 15.5 } [ "1111.1p0" bin> ] unit-test
+{ 15.53125 } [ "1111.10001p0" bin> ] unit-test
+{ -15.5 } [ "-1111.1p0" bin> ] unit-test
+{ 15.5 } [ "1111.1p0" bin> ] unit-test
+{ -15.5 } [ "-1111.1p0" bin> ] unit-test
+{ 62.0 } [ "1111.1p2" bin> ] unit-test
+{ 3.875 } [ "1111.1p-2" bin> ] unit-test
+{ $[ 1 bits>double ] } [ "1.0p-1074" bin> ] unit-test
+{ 0.0 } [ "1.0p-1075" bin> ] unit-test
+{ 1/0. } [ "1.0p1024" bin> ] unit-test
+{ -1/0. } [ "-1.0p1024" bin> ] unit-test
+
+{ 1.0 } [ "1.0p0" oct> ] unit-test
+{ 1.5 } [ "1.4p0" oct> ] unit-test
+{ 1.875 } [ "1.7p0" oct> ] unit-test
+{ 1.90625 } [ "1.72p0" oct> ] unit-test
+{ 1.03125 } [ "1.02p0" oct> ] unit-test
+{ 15.5 } [ "17.4p0" oct> ] unit-test
+{ 15.53125 } [ "17.42p0" oct> ] unit-test
+{ -15.5 } [ "-17.4p0" oct> ] unit-test
+{ 15.5 } [ "17.4p0" oct> ] unit-test
+{ -15.5 } [ "-17.4p0" oct> ] unit-test
+{ 62.0 } [ "17.4p2" oct> ] unit-test
+{ 3.875 } [ "17.4p-2" oct> ] unit-test
+{ $[ 1 bits>double ] } [ "1.0p-1074" oct> ] unit-test
+{ 0.0 } [ "1.0p-1075" oct> ] unit-test
+{ 1/0. } [ "1.0p1024" oct> ] unit-test
+{ -1/0. } [ "-1.0p1024" oct> ] unit-test
+
 { 0 } [ "0" string>number ] unit-test
 { 0 } [ "00" string>number ] unit-test
 { 0 } [ "0,000" string>number ] unit-test
index 82886bb2d1d54ba4644b61f7b9c66ffe39344867..ecd1515750808f1b5b199bd991271463582233f0 100644 (file)
@@ -107,7 +107,7 @@ ARTICLE: "syntax-floats" "Float syntax"
 }
 "A Not-a-number literal with an arbitrary payload can also be input:"
 { $subsections POSTPONE: NAN: }
-"Hexadecimal float literals are also supported. These consist of a hexadecimal literal with a decimal point and a mandatory base-two exponent expressed as a decimal number after " { $snippet "p" } " or " { $snippet "P" } ":"
+"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 = ."
     "t"
@@ -120,6 +120,14 @@ ARTICLE: "syntax-floats" "Float syntax"
     "10.125 0x1.44p3 = ."
     "t"
 }
+{ $example
+    "10.125 0b1.01001p3 = ."
+    "t"
+}
+{ $example
+    "10.125 0o1.22p3 = ."
+    "t"
+}
 "The normalized hex form " { $snippet "±0x1.MMMMMMMMMMMMMp±EEEE" } " allows any floating-point number to be specified precisely. The values of MMMMMMMMMMMMM and EEEE map directly to the mantissa and exponent fields of the binary IEEE 754 representation."
 $nl
 "More information on floats can be found in " { $link "floats" } "." ;