Raymond Toy pushed to branch issue-480-double-double-hex-printer at cmucl / cmucl

Commits:

3 changed files:

Changes:

  • src/code/ext-code.lisp
    ... ... @@ -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
    

  • src/i18n/locale/cmucl.pot
    No preview for this file type
  • tests/extensions.lisp
    ... ... @@ -84,6 +84,17 @@
    84 84
       (assert-equal "0x1.fffffffffffff8p-1w"
    
    85 85
                     (ext:float-to-hex-string (- 1.0w0 (scale-float 1.0w0 -54)))))
    
    86 86
     
    
    87
    +(define-test write-double-double-special
    
    88
    +  (assert-equal "0x1.0p+infw"
    
    89
    +                (ext:float-to-hex-string (float ext:double-float-positive-infinity 1w0)))
    
    90
    +  (assert-equal "-0x1.0p+infw"
    
    91
    +                (ext:float-to-hex-string (float ext:double-float-negative-infinity 1w0)))
    
    92
    +  (assert-equal "0x0.0p+nanw"
    
    93
    +                (ext:float-to-hex-string
    
    94
    +                  (ext:with-float-traps-masked (:invalid)
    
    95
    +                    (- (float ext:double-float-positive-infinity 1w0)
    
    96
    +                       (float ext:double-float-positive-infinity 1w0))))))
    
    97
    +
    
    87 98
     
    
    88 99
     ;;; ---- read-hex-float tests ------------------------------------------------
    
    89 100