*read-default-float-format*
∗read-default-float-format∗ Variable
Value Type:
one of the atomic type specifiers short-float, single-float, double-float, or long-float, or else some other type specifier defined by the implementation to be acceptable.
Initial Value:
The symbol single-float.
Description:
Controls the floating-point format that is to be used when reading a floating-point number that has no exponent marker or that has e or E for an exponent marker . Other exponent markers explicitly prescribe the floating-point format to be used.
The printer uses *read-default-float-format* to guide the choice of exponent markers when printing floating-point numbers.
Examples:
(let ((\*read-default-float-format\* ’double-float))
(read-from-string "(1.0 1.0e0 1.0s0 1.0f0 1.0d0 1.0L0)"))
→ (1.0 1.0 1.0 1.0 1.0 1.0) ;Implementation has float format F.
→ (1.0 1.0 1.0s0 1.0 1.0 1.0) ;Implementation has float formats S and F. → (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0d0) ;Implementation has float formats F and D. → (1.0d0 1.0d0 1.0s0 1.0 1.0d0 1.0d0) ;Implementation has float formats S, F, D. → (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0L0) ;Implementation has float formats F, D, L. → (1.0d0 1.0d0 1.0s0 1.0 1.0d0 1.0L0) ;Implementation has formats S, F, D, L.
*∗***read-eval***∗ Variable*
Value Type:
a generalized boolean.
Initial Value:
true.
Description:
If it is true, the #. reader macro has its normal effect. Otherwise, that reader macro signals an error of type reader-error.
See Also:
*print-readably*Notes:
If *read-eval* is false and *print-readably* is true, any method for print-object that would output a reference to the #. reader macro either outputs something different or signals an error of type print-not-readable.
Expanded Reference: *read-default-float-format*
Default behavior
*read-default-float-format* controls the type of float produced when reading a floating-point number that has no exponent marker or uses e/E. Its initial value is single-float.
*read-default-float-format*
=> SINGLE-FLOAT
(type-of (read-from-string "1.0"))
=> SINGLE-FLOAT
Changing the default float format
By binding *read-default-float-format* to double-float, numbers without an explicit exponent marker are read as double floats.
(let ((*read-default-float-format* 'double-float))
(type-of (read-from-string "1.0")))
=> DOUBLE-FLOAT
(let ((*read-default-float-format* 'double-float))
(type-of (read-from-string "3.14e0")))
=> DOUBLE-FLOAT
Explicit exponent markers override the default
The exponent markers s, f, d, and l always specify their corresponding float types regardless of *read-default-float-format*.
(let ((*read-default-float-format* 'double-float))
(list (type-of (read-from-string "1.0")) ; uses default
(type-of (read-from-string "1.0s0")) ; short-float
(type-of (read-from-string "1.0f0")) ; single-float
(type-of (read-from-string "1.0d0")) ; double-float
(type-of (read-from-string "1.0l0")))) ; long-float
=> (DOUBLE-FLOAT SHORT-FLOAT SINGLE-FLOAT DOUBLE-FLOAT LONG-FLOAT)
;; Note: some implementations merge certain float types
Effect on the printer
*read-default-float-format* also influences the printer: when printing a float whose type matches the default format, the printer may omit the exponent marker or use E.
(let ((*read-default-float-format* 'single-float))
(format nil "~S ~S" 1.0 1.0d0))
=> "1.0 1.0d0"
(let ((*read-default-float-format* 'double-float))
(format nil "~S ~S" 1.0 1.0d0))
=> "1.0f0 1.0"
;; The double-float is now the default so it drops the marker;
;; the single-float must use f0 to distinguish itself