| ... |
... |
@@ -1572,35 +1572,48 @@ |
|
1572
|
1572
|
(format-princ stream number nil nil w 1 0 pad)))
|
|
1573
|
1573
|
|
|
1574
|
1574
|
|
|
|
1575
|
+(defmacro def-format-ryu (name (stream number &rest args) &body body)
|
|
|
1576
|
+ (multiple-value-bind (docstring forms)
|
|
|
1577
|
+ (if (and (stringp (first body)) (rest body))
|
|
|
1578
|
+ (values (list (first body)) (rest body))
|
|
|
1579
|
+ (values nil body))
|
|
|
1580
|
+ `(defun ,name (,stream ,number ,@args)
|
|
|
1581
|
+ ,@docstring
|
|
|
1582
|
+ (cond
|
|
|
1583
|
+ ((and (floatp ,number)
|
|
|
1584
|
+ (or (float-infinity-p ,number)
|
|
|
1585
|
+ (float-nan-p ,number)))
|
|
|
1586
|
+ (prin1 number ,stream))
|
|
|
1587
|
+ (t
|
|
|
1588
|
+ ,@forms)
|
|
|
1589
|
+ (values)))))
|
|
|
1590
|
+
|
|
|
1591
|
+(defmacro def-format-aux (base-name (stream number &rest args) &body body)
|
|
|
1592
|
+ (let ((docstring
|
|
|
1593
|
+ (if (and (stringp (first body)) (rest body))
|
|
|
1594
|
+ (list (first body))
|
|
|
1595
|
+ nil)))
|
|
|
1596
|
+ (let ((defun-name (symbolicate base-name "-AUX"))
|
|
|
1597
|
+ (name-ryu (symbolicate base-name "-RYU"))
|
|
|
1598
|
+ (name-bd (symbolicate base-name "-AUX-BD")))
|
|
|
1599
|
+ `(defun ,defun-name (,stream ,number ,@args)
|
|
|
1600
|
+ ,@docstring
|
|
|
1601
|
+ (cond
|
|
|
1602
|
+ ((and lisp::*use-ryu-printer*
|
|
|
1603
|
+ (typep ,number '(or single-float double-float)))
|
|
|
1604
|
+ (,name-ryu ,stream ,number ,@args))
|
|
|
1605
|
+ (t
|
|
|
1606
|
+ (,name-bd ,stream, number ,@args)))))))
|
|
|
1607
|
+
|
|
1575
|
1608
|
;;; We return true if we overflowed, so that ~G can output the overflow char
|
|
1576
|
1609
|
;;; instead of spaces.
|
|
1577
|
1610
|
;;;
|
|
1578
|
|
-(defun format-fixed-aux (stream number w d k ovf pad atsign)
|
|
1579
|
|
- (declare (type float number))
|
|
1580
|
|
- ;; Dispatch to either the Burger and Dybvig implementation or the
|
|
1581
|
|
- ;; Ryu-based implementation. The Ryu code only handles single- and
|
|
1582
|
|
- ;; double-float values, so any other float type (notably
|
|
1583
|
|
- ;; DOUBLE-DOUBLE-FLOAT) always falls through to the B&D path.
|
|
1584
|
|
- (cond
|
|
1585
|
|
- ((and lisp::*use-ryu-printer*
|
|
1586
|
|
- (or (null k) (zerop k))
|
|
1587
|
|
- (typep number '(or single-float double-float)))
|
|
1588
|
|
- (format-fixed-ryu stream number w d k ovf pad atsign))
|
|
1589
|
|
- (t
|
|
1590
|
|
- (format-fixed-aux-bd stream number w d k ovf pad atsign))))
|
|
1591
|
|
-
|
|
1592
|
|
-(defun format-fixed-ryu (stream number w d k ovf pad atsign)
|
|
|
1611
|
+(def-format-aux format-fixed (stream number w d k ovf pad atsign))
|
|
|
1612
|
+
|
|
|
1613
|
+(def-format-ryu format-fixed-ryu (stream number w d k ovf pad atsign)
|
|
1593
|
1614
|
"Ryu-based implementation of the ~F directive. Delegates to
|
|
1594
|
1615
|
LISP::FORMAT-F, which returns the formatted field as a string."
|
|
1595
|
|
- (cond
|
|
1596
|
|
- ((and (floatp number)
|
|
1597
|
|
- (or (float-infinity-p number)
|
|
1598
|
|
- (float-nan-p number)))
|
|
1599
|
|
- (prin1 number stream)
|
|
1600
|
|
- nil)
|
|
1601
|
|
- (t
|
|
1602
|
|
- (lisp::format-f stream number w d (or k 0) ovf pad atsign) stream)))
|
|
1603
|
|
- nil)
|
|
|
1616
|
+ (lisp::format-f stream number w d (or k 0) ovf pad atsign))
|
|
1604
|
1617
|
|
|
1605
|
1618
|
(defun format-fixed-aux-bd (stream number w d k ovf pad atsign)
|
|
1606
|
1619
|
"Burger and Dybvig based implementation of the ~F directive."
|
| ... |
... |
@@ -1884,40 +1897,19 @@ |
|
1884
|
1897
|
(write-string estr stream))))))))
|
|
1885
|
1898
|
(values))
|
|
1886
|
1899
|
|
|
1887
|
|
-(defun format-exp-ryu (stream number w d e k ovf pad marker atsign)
|
|
|
1900
|
+(def-format-ryu format-exp-ryu (stream number w d e k ovf pad marker atsign)
|
|
1888
|
1901
|
"Ryu-based implementation of the ~E directive. Delegates to
|
|
1889
|
1902
|
LISP::FORMAT-E, which returns the formatted field as a string."
|
|
1890
|
|
- (cond
|
|
1891
|
|
- ((and (floatp number)
|
|
1892
|
|
- (or (float-infinity-p number)
|
|
1893
|
|
- (float-nan-p number)))
|
|
1894
|
|
- (prin1 number stream))
|
|
1895
|
|
- (t
|
|
1896
|
|
- ;; LISP::FORMAT-E uses a literal #\d as the default exponent
|
|
1897
|
|
- ;; marker when EXPONENTCHAR is NIL, but the CL ~E directive
|
|
1898
|
|
- ;; chooses the marker based on the value's type and
|
|
1899
|
|
- ;; *READ-DEFAULT-FLOAT-FORMAT* (see FORMAT-EXPONENT-MARKER).
|
|
1900
|
|
- ;; Resolve the default here so the same rule applies.
|
|
1901
|
|
- (lisp::format-e stream number w d e k ovf pad
|
|
1902
|
|
- (or marker (format-exponent-marker number))
|
|
1903
|
|
- atsign)))
|
|
1904
|
|
- (values))
|
|
1905
|
|
-
|
|
1906
|
|
-(defun format-exp-aux (stream number w d e k ovf pad marker atsign)
|
|
1907
|
|
- ;; Dispatch to either the Burger and Dybvig implementation or the
|
|
1908
|
|
- ;; Ryu-based implementation. The Ryu code only handles single- and
|
|
1909
|
|
- ;; double-float values, so any other float type (notably
|
|
1910
|
|
- ;; DOUBLE-DOUBLE-FLOAT) always falls through to the B&D path.
|
|
1911
|
|
- (cond
|
|
1912
|
|
- ((and lisp::*use-ryu-printer*
|
|
1913
|
|
- (floatp number)
|
|
1914
|
|
- (typep number '(or single-float double-float))
|
|
1915
|
|
- (not (or (float-infinity-p number)
|
|
1916
|
|
- (float-nan-p number))))
|
|
1917
|
|
- (format-exp-ryu stream number w d e k ovf pad marker atsign))
|
|
1918
|
|
- (t
|
|
1919
|
|
- (format-exp-aux-bd stream number w d e k ovf pad marker atsign))))
|
|
|
1903
|
+ ;; LISP::FORMAT-E uses a literal #\d as the default exponent
|
|
|
1904
|
+ ;; marker when EXPONENTCHAR is NIL, but the CL ~E directive
|
|
|
1905
|
+ ;; chooses the marker based on the value's type and
|
|
|
1906
|
+ ;; *READ-DEFAULT-FLOAT-FORMAT* (see FORMAT-EXPONENT-MARKER).
|
|
|
1907
|
+ ;; Resolve the default here so the same rule applies.
|
|
|
1908
|
+ (lisp::format-e stream number w d e k ovf pad
|
|
|
1909
|
+ (or marker (format-exponent-marker number))
|
|
|
1910
|
+ atsign))
|
|
1920
|
1911
|
|
|
|
1912
|
+(def-format-aux format-exp (stream number w d e k ovf pad marker atsign))
|
|
1921
|
1913
|
|
|
1922
|
1914
|
(def-format-directive #\G (colonp atsignp params)
|
|
1923
|
1915
|
(when colonp
|
| ... |
... |
@@ -1954,33 +1946,14 @@ |
|
1954
|
1946
|
|
|
1955
|
1947
|
|
|
1956
|
1948
|
;;; toy@rtp.ericsson.se: Same change as for format-exp-aux.
|
|
1957
|
|
-(defun format-general-aux (stream number w d e k ovf pad marker atsign)
|
|
1958
|
|
- ;; Dispatch to either the Burger and Dybvig implementation or the
|
|
1959
|
|
- ;; Ryu-based implementation. The Ryu code only handles single- and
|
|
1960
|
|
- ;; double-float values, so any other float type (notably
|
|
1961
|
|
- ;; DOUBLE-DOUBLE-FLOAT) always falls through to the B&D path.
|
|
1962
|
|
- (cond
|
|
1963
|
|
- ((and lisp::*use-ryu-printer*
|
|
1964
|
|
- (floatp number)
|
|
1965
|
|
- (typep number '(or single-float double-float)))
|
|
1966
|
|
- (format-general-ryu stream number w d e k ovf pad marker atsign))
|
|
1967
|
|
- (t
|
|
1968
|
|
- (format-general-aux-bd stream number w d e k ovf pad marker atsign))))
|
|
1969
|
|
-
|
|
1970
|
|
-(defun format-general-ryu (stream number w d e k ovf pad marker atsign)
|
|
|
1949
|
+(def-format-aux format-general (stream number w d e k ovf pad marker atsign))
|
|
|
1950
|
+
|
|
|
1951
|
+(def-format-ryu format-general-ryu (stream number w d e k ovf pad marker atsign)
|
|
1971
|
1952
|
"Ryu-based implementation of the ~G directive. Delegates to
|
|
1972
|
1953
|
LISP::FORMAT-G, which returns the formatted field as a string."
|
|
1973
|
|
- (cond
|
|
1974
|
|
- ((and (floatp number)
|
|
1975
|
|
- (or (float-infinity-p number)
|
|
1976
|
|
- (float-nan-p number)))
|
|
1977
|
|
- (prin1 number stream)
|
|
1978
|
|
- nil)
|
|
1979
|
|
- (t
|
|
1980
|
|
- (lisp::format-g stream number w d e (or k 1) ovf pad
|
|
1981
|
|
- (or marker (format-exponent-marker number))
|
|
1982
|
|
- atsign)))
|
|
1983
|
|
- (values))
|
|
|
1954
|
+ (lisp::format-g stream number w d e (or k 1) ovf pad
|
|
|
1955
|
+ (or marker (format-exponent-marker number))
|
|
|
1956
|
+ atsign))
|
|
1984
|
1957
|
|
|
1985
|
1958
|
(defun format-general-aux-bd (stream number w d e k ovf pad marker atsign)
|
|
1986
|
1959
|
"Burger and Dybvig based implementation of the ~G directive."
|