| ... |
... |
@@ -36,7 +36,7 @@ |
|
36
|
36
|
|
|
37
|
37
|
(defun write-hex-float-double (x stream)
|
|
38
|
38
|
"Print a single- or double-float in hex format onto STREAM.
|
|
39
|
|
- Float type and mantissa width are derived from the type of X."
|
|
|
39
|
+ Float type and mantissa width are derived from the type of X."
|
|
40
|
40
|
(multiple-value-bind (mantissa-bits suffix-char min-c-exp)
|
|
41
|
41
|
(etypecase x
|
|
42
|
42
|
(single-float (values (1- (float-digits 1f0)) #\f (- vm:single-float-bias)))
|
| ... |
... |
@@ -111,9 +111,7 @@ |
|
111
|
111
|
|
|
112
|
112
|
#+double-double
|
|
113
|
113
|
(defun write-hex-float-double-double (x stream)
|
|
114
|
|
- "Print a double-double-float in hex format onto STREAM.
|
|
115
|
|
- Reconstructs the full significand from hi and lo components
|
|
116
|
|
- using exact integer arithmetic before formatting."
|
|
|
114
|
+ "Print a double-double-float in hex format onto STREAM."
|
|
117
|
115
|
(let* ((hi (kernel:double-double-hi x))
|
|
118
|
116
|
(lo (kernel:double-double-lo x)))
|
|
119
|
117
|
;; Print the sign, but not for NaN since float-sign is unreliable there.
|
| ... |
... |
@@ -196,7 +194,8 @@ |
|
196
|
194
|
;;; Writes a float value (single, double, or double-double) in hex
|
|
197
|
195
|
;;; format to a stream, defaulting to *standard-output*.
|
|
198
|
196
|
(defun write-hex-float (x &optional (stream *standard-output*))
|
|
199
|
|
- "Write float X to STREAM in C-style hex format. STREAM defaults to *standard-output*.
|
|
|
197
|
+ "Write float X to STREAM in C-style hex format. STREAM defaults to
|
|
|
198
|
+ *standard-output*.
|
|
200
|
199
|
|
|
201
|
200
|
single-float => 0x<mantissa>p<exp>f
|
|
202
|
201
|
double-float => 0x<mantissa>p<exp>
|
| ... |
... |
@@ -230,10 +229,11 @@ |
|
230
|
229
|
;;;
|
|
231
|
230
|
;;; Function that can be used in a FORMAT ~/
|
|
232
|
231
|
(defun format-hex-float (stream x colonp atsignp &rest args)
|
|
233
|
|
- "Format function for use with ~/package:format-hex-float/.
|
|
|
232
|
+ "Format function for use with ~/ext:format-hex-float/.
|
|
234
|
233
|
Ignores colon modifier. At-sign modifier forces a leading + sign on
|
|
235
|
|
- non-negative values. Example: (format t \"~@/ext:format-hex-float/\"
|
|
236
|
|
- 3.0d0) => +0x1.8p+1"
|
|
|
234
|
+ non-negative values.
|
|
|
235
|
+
|
|
|
236
|
+ Example: (format t \"~@/ext:format-hex-float/\" 3.0d0) => +0x1.8p+1"
|
|
237
|
237
|
(declare (ignore colonp args))
|
|
238
|
238
|
(when (and atsignp
|
|
239
|
239
|
(not (float-nan-p x))
|
| ... |
... |
@@ -393,8 +393,10 @@ |
|
393
|
393
|
(defun read-hex-float-from-string (s &key (start 0) end)
|
|
394
|
394
|
"Read a C-style hex float from string S.
|
|
395
|
395
|
START and END bound the region to read (default: entire string).
|
|
|
396
|
+ Signals HEX-FLOAT-PARSE-ERROR on malformed input.
|
|
|
397
|
+
|
|
396
|
398
|
Returns two values: the float and the index of the first character
|
|
397
|
|
- not consumed. Signals HEX-FLOAT-PARSE-ERROR on malformed input."
|
|
|
399
|
+ not consumed."
|
|
398
|
400
|
(with-input-from-string (stream s :start start :end end)
|
|
399
|
401
|
(values (read-hex-float-from-stream stream)
|
|
400
|
402
|
(file-position stream))))
|
| ... |
... |
@@ -403,7 +405,7 @@ |
|
403
|
405
|
;;; READ-HEX-FLOAT -- Public
|
|
404
|
406
|
;;;
|
|
405
|
407
|
;;; Read a C-style hex float number from either a string or a stream.
|
|
406
|
|
-(defun ext:read-hex-float (stream-or-string &key (start 0) end)
|
|
|
408
|
+(defun read-hex-float (stream-or-string &key (start 0) end)
|
|
407
|
409
|
"Read a C-style hex float from STREAM-OR-STRING.
|
|
408
|
410
|
If a string, START and END bound the region to read. When reading
|
|
409
|
411
|
from a string, returns two values: the float and the index of the
|