Commit 9039f847 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

base: Fix handling of showEFloat (Just 0)

Previously `showEFloat (Just 0) pi ""` would produce `3.0e0`. Of
course, this
blatantly disrespects the user's request to print with zero digits of
precision.
Fix this.

This is tested by base's `num008` testcase.

Test Plan: Validate

Reviewers: hvr

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #15115

Differential Revision: https://phabricator.haskell.org/D4665
parent 6ab7cf99
...@@ -690,6 +690,16 @@ formatRealFloatAlt fmt decs alt x ...@@ -690,6 +690,16 @@ formatRealFloatAlt fmt decs alt x
[d] -> d : ".0e" ++ show_e' [d] -> d : ".0e" ++ show_e'
(d:ds') -> d : '.' : ds' ++ "e" ++ show_e' (d:ds') -> d : '.' : ds' ++ "e" ++ show_e'
[] -> errorWithoutStackTrace "formatRealFloat/doFmt/FFExponent: []" [] -> errorWithoutStackTrace "formatRealFloat/doFmt/FFExponent: []"
Just 0 ->
-- handle this case specifically since we need to omit the
-- decimal point as well (#15115)
case is of
[0] -> "0e0"
_ ->
let
(ei,is') = roundTo base 1 is
d:_ = map intToDigit (if ei > 0 then init is' else is')
in d : 'e' : show (e-1+ei)
Just dec -> Just dec ->
let dec' = max dec 1 in let dec' = max dec 1 in
case is of case is of
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
* `asinh` for `Float` and `Double` is now numerical stable in the face of * `asinh` for `Float` and `Double` is now numerical stable in the face of
large negative arguments (#14927) large negative arguments (#14927)
* `Numeric.showEFloat (Just 0)` now respects the user's requested precision.
(#15115)
## 4.11.1.0 *TBA* ## 4.11.1.0 *TBA*
* Bundled with GHC 8.4.2 * Bundled with GHC 8.4.2
......
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
4.2000000e-2 4.2000000e-2
1.8217369e0 1.8217369e0
1.8217369e-300 1.8217369e-300
0.0e0 0e0
4.2e2 4e2
4.2e1 4e1
4.2e0 4e0
4.2e-1 4e-1
4.2e-2 4e-2
1.8e0 2e0
1.8e-300 2e-300
0.0e0 0.0e0
4.2e2 4.2e2
4.2e1 4.2e1
...@@ -59,9 +59,9 @@ ...@@ -59,9 +59,9 @@
42 42
4 4
0 0
4.2e-2 4e-2
2 2
1.8e-300 2e-300
0.0 0.0
420.0 420.0
42.0 42.0
...@@ -79,14 +79,14 @@ ...@@ -79,14 +79,14 @@
4.2000000e-2 4.2000000e-2
1.8217369e0 1.8217369e0
0.0000000e0 0.0000000e0
0.0e0 0e0
4.2e2 4e2
4.2e1 4e1
4.2e0 4e0
4.2e-1 4e-1
4.2e-2 4e-2
1.8e0 2e0
0.0e0 0e0
0.0e0 0.0e0
4.2e2 4.2e2
4.2e1 4.2e1
...@@ -132,7 +132,7 @@ ...@@ -132,7 +132,7 @@
42 42
4 4
0 0
4.2e-2 4e-2
2 2
0 0
0.0 0.0
...@@ -144,5 +144,5 @@ ...@@ -144,5 +144,5 @@
1.8217369 1.8217369
0.0 0.0
[0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,1.8217369e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8,1.8e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369128763983,1.821736912876398e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.0,0.0,0.0,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369128763983,1.821736912876398e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,1.8217369e-300,0.0,420.0,42.0,4.0,0.0,4.2e-2,2.0,1.8e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369128763983,1.821736912876398e-300] [0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,1.8217369e-300,0.0,400.0,40.0,4.0,0.4,4.0e-2,2.0,2.0e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369128763983,1.821736912876398e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.0,0.0,0.0,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369128763983,1.821736912876398e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,1.8217369e-300,0.0,420.0,42.0,4.0,0.0,4.0e-2,2.0,2.0e-300,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369128763983,1.821736912876398e-300]
[0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.0,0.0,0.0,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.0,0.0,4.2e-2,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0] [0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,400.0,40.0,4.0,0.4,4.0e-2,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.0,0.0,0.0,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0,0.0,420.0,42.0,4.0,0.0,4.0e-2,2.0,0.0,0.0,420.0,42.0,4.2,0.42,4.2e-2,1.8217369,0.0]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment