]> gitweb.factorcode.org Git - factor.git/commitdiff
math, syntax: document hexadecimal float literal syntax
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 13 Sep 2009 02:18:17 +0000 (21:18 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 13 Sep 2009 02:18:17 +0000 (21:18 -0500)
core/math/parser/parser-docs.factor
core/syntax/syntax-docs.factor

index 1e3ff4f9960a0d606fadc831ead89bae95880c58..af4c712836099df69a9d3dfca74bb78f847ae1c2 100644 (file)
@@ -5,7 +5,7 @@ IN: math.parser
 ARTICLE: "number-strings" "Converting between numbers and strings"
 "These words only convert between real numbers and strings. Complex numbers are constructed by the parser (" { $link "parser" } ") and printed by the prettyprinter (" { $link "prettyprint" } ")."
 $nl
-"Note that only integers can be converted to and from strings using a representation other than base 10. Calling a word such as " { $link >oct } " on a float will give a result in base 10."
+"Integers can be converted to and from arbitrary bases. Floating point numbers can only be converted to and from base 10 and 16."
 $nl
 "Converting numbers to strings:"
 { $subsection number>string }
@@ -93,7 +93,19 @@ HELP: >oct
 
 HELP: >hex
 { $values { "n" real } { "str" string } }
-{ $description "Outputs a string representation of a number using base 16." } ;
+{ $description "Outputs a string representation of a number using base 16." }
+{ $examples
+    { $example
+        "USING: math.parser prettyprint ;"
+        "3735928559 >hex ."
+        "\"deadbeef\""
+    }
+    { $example
+        "USING: math.parser prettyprint ;"
+        "-15.5 >hex ."
+        "\"-f.8p0\""
+    }
+} ;
 
 HELP: string>float ( str -- n/f )
 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
index 0a11f62c16801362e7db12bb17a86d9d9cc3ef9a..e34fb0957f123b9e71f9266400987fde4fdd8ec6 100644 (file)
@@ -59,20 +59,25 @@ ARTICLE: "syntax-ratios" "Ratio syntax"
 "More information on ratios can be found in " { $link "rationals" } ;
 
 ARTICLE: "syntax-floats" "Float syntax"
-"Floating point literals must contain a decimal point, and may contain an exponent:"
+"Floating point literals can be input in base 10 or 16. Base 10 literals must contain a decimal point, and may contain an exponent after " { $snippet "e" } ":"
 { $code
     "10.5"
     "-3.1456"
     "7.e13"
     "1.0e-5"
 }
-"There are three special float values:"
+"Base 16 literals use " { $snippet "p" } " instead of " { $snippet "e" } " for the exponent, which is still decimal:"
+{ $example
+    "10.125 HEX: 1.44p3 = ."
+    "t"
+}
+"Syntax for special float values:"
 { $table
 { "Positive infinity" { $snippet "1/0." } }
 { "Negative infinity" { $snippet "-1/0." } }
 { "Not-a-number" { $snippet "0/0." } }
 }
-"A Not-a-number with an arbitrary payload can be parsed in:"
+"A Not-a-number with an arbitrary payload can also be parsed in:"
 { $subsection POSTPONE: NAN: }
 "More information on floats can be found in " { $link "floats" } "." ;