read hex floats
0x1.8p3 was no number to the reader, so it became a symbol C got inside |pipes|, and _ could not type it. It reads now as a literal written as it was: the digits of a double's own bits, which no decimal rounds to.
This commit is contained in:
@@ -827,6 +827,10 @@ whitespace aside, THEN?"
|
||||
(test-assert "a float keeps its digits, which a double would round"
|
||||
(emits? (in-fn "(var x (long double) 3.14159265358979323846264338327950288L)")
|
||||
"x = 3.14159265358979323846264338327950288L;"))
|
||||
(test-assert "a hex float is written as it was"
|
||||
(emits? (in-fn "(var x double 0x1.8p3)") "x = 0x1.8p3;"))
|
||||
(test-assert "suffix and all"
|
||||
(emits? (in-fn "(var x float -0x1p-2f)") "x = -0x1p-2f;"))
|
||||
(test-assert "grouped digits reach C ungrouped"
|
||||
(emits? (in-fn "(var x float 1_000.5f)") "x = 1000.5f;"))
|
||||
(test-assert "a minus is C's own"
|
||||
|
||||
@@ -76,6 +76,10 @@
|
||||
(test "nor a float" "C has no literal for this number" (read-error "1e39f"))
|
||||
(test "but a long double may be wider than a double"
|
||||
#f (read-error "1e400L"))
|
||||
(test "a hex float is held to the same ranges"
|
||||
"C has no literal for this number" (read-error "0x1p1024"))
|
||||
(test "a float's too" "C has no literal for this number" (read-error "0x1p128f"))
|
||||
(test "and a long double's" #f (read-error "0x1p1024L"))
|
||||
(test "nor an infinity" "C has no literal for this number" (read-error "-inf.0"))
|
||||
(test "nor a NaN" "C has no literal for this number" (read-error "+nan.0"))
|
||||
(test "nor a complex number" "C has no literal for this number" (read-error "1+2i"))
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
"widths: 1 1 1"
|
||||
"a float stays a float: 1"
|
||||
"radix with suffix: 255 5"
|
||||
"by magnitude: 4000000000 18446744073709551615")
|
||||
"by magnitude: 4000000000 18446744073709551615"
|
||||
"hex floats: 12 0.25 1")
|
||||
(return 0)
|
||||
|
||||
;;; A number is written the way C writes it, suffix included, and `_'
|
||||
@@ -36,4 +37,9 @@
|
||||
(var big _ 4000000000)
|
||||
(var mask _ 0xFFFFFFFFFFFFFFFF)
|
||||
(printf "by magnitude: %lld %llu\n" big mask)
|
||||
|
||||
;; a double's own digits, which no decimal has to round to
|
||||
(var twelve _ 0x1.8p3)
|
||||
(var quarter _ 0x1p-2f)
|
||||
(printf "hex floats: %g %g %d\n" twelve quarter (== (sizeof quarter) (sizeof float)))
|
||||
(return 0))
|
||||
|
||||
Reference in New Issue
Block a user