Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit cdd8252

Browse files
committed
show of Float and Double closer to what ghc does
1 parent d2603df commit cdd8252

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

EHC/src/rts/bc/prim.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ PRIM GB_NodePtr primShowFloat( Float w )
426426
{
427427
char buf[sizeof(Float)*10] ;
428428
char *s = buf ;
429-
sprintf( s, "%f", w ) ;
429+
sprintf( s, "%-1.8g", w ) ;
430430

431431
GB_NodePtr n ;
432432
int sz = strlen(buf) + 1 ; // ??? why +1
@@ -440,7 +440,7 @@ PRIM GB_NodePtr primShowDouble( Double w )
440440
{
441441
char buf[sizeof(Double)*10] ;
442442
char *s = buf ;
443-
sprintf( s, "%lf", w ) ;
443+
sprintf( s, "%-1.16g", w ) ;
444444

445445
GB_NodePtr n ;
446446
int sz = strlen(buf) + 1 ; // ??? why +1

EHC/test/regress/99/FloatPrint1.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{- ----------------------------------------------------------------------------------------
2+
what : Floating functions, on Float
3+
expected: print with as much precision as possible (used to be 5 after comma)
4+
---------------------------------------------------------------------------------------- -}
5+
6+
{-
7+
8+
With GHC (8.0.1): 1.4142135623730951
9+
with UHC: 1.414214
10+
11+
Is there any reason for the difference?
12+
13+
Blocking agda/agda#1856.
14+
15+
-}
16+
17+
module Main where
18+
19+
main = do
20+
print $ sqrt (2.0 :: Float)
21+
print $ sqrt (2.0 :: Double)
22+
print $ sqrt (20000000.0 :: Float)
23+
print $ sqrt (20000000.0 :: Double)
24+
print $ sqrt (0.00000002 :: Float)
25+
print $ sqrt (0.00000002 :: Double)
26+
print $ sqrt (20000000000000000000.0 :: Float)
27+
print $ sqrt (20000000000000000000.0 :: Double)
28+
print $ sqrt (0.00000000000000000002 :: Float)
29+
print $ sqrt (0.00000000000000000002 :: Double)
30+
print $ (2.0 :: Float)
31+
print $ (2.0 :: Double)
32+
print $ (20000000.0 :: Float)
33+
print $ (20000000.0 :: Double)
34+
print $ (0.00000002 :: Float)
35+
print $ (0.00000002 :: Double)
36+
print $ (20000000000000000000.0 :: Float)
37+
print $ (20000000000000000000.0 :: Double)
38+
print $ (0.00000000000000000002 :: Float)
39+
print $ (0.00000000000000000002 :: Double)

0 commit comments

Comments
 (0)