File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,12 +121,17 @@ strings round-trip readably.")
121121 caller's formatting pass.")
122122 (private double-str)
123123 (hidden double-str)
124- (doc double-str "renders a `Double` with a decimal point preserved.
125- `Double.str 10.0` returns `\"10\"`, which round-trips as an `Int`; we
126- append `.0` so the source reads as a double again.")
124+ (doc double-str "renders a `Double` keeping it lexically a double.
125+ `Double.str 10.0` returns `\"10\"`, which would round-trip as an `Int`;
126+ scientific notation (`1e+09`) round-trips fine on its own. Append `.0`
127+ only when the output has neither a decimal point nor an exponent.")
127128 (defn double-str [d]
128129 (let-do [s (Double.str d)]
129- (if (String.contains? &s \.) s (String.append &s ".0"))))
130+ (if (or
131+ (String.contains? &s \.)
132+ (or (String.contains? &s \e) (String.contains? &s \E)))
133+ s
134+ (String.append &s ".0"))))
130135
131136 (defn str [a]
132137 (match-ref a
Original file line number Diff line number Diff line change 156156 "10.0"
157157 &(Located.str &(first-form "10.0"))
158158 "10.0 round-trips as Double, not Int")
159+ ; Big doubles render in scientific notation; no `.0` should be
160+ ; appended in that case (it would produce invalid `1e+09.0`).
161+ (assert-equal t
162+ "1e+09"
163+ &(Located.str &(first-form "999999999.0"))
164+ "large Double keeps scientific notation, no spurious .0")
159165
160166 ; --- end positions track the byte after the form ---
161167 (assert-equal t
You can’t perform that action at this time.
0 commit comments