Commit a03c70bc authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-29 14:34:09 by simonmar]

Expand this test to show a range of floats and doubles using
showEFLoat, showFFloat and showGFloat with a range of precisions, and
also attempt to "read" back the results.
parent 517e555a
-- showing floats
-- showing/reading floats
--
module Main(main) where
import Numeric
main =
do
putStrLn (showEFloat (Just 7) (1.82173691287639817263897126389712638972163e-300::Double) [])
putStrLn (showFFloat (Just 7) (1.82173691287639817263897126389712638972163::Double) [])
putStrLn (showGFloat (Just 7) (1.82173691287639817263897126389712638972163e-300::Double) [])
putStrLn (showEFloat (Just 7) (1.82173691287639817263897126389712638972163e-300::Float) [])
putStrLn (showEFloat (Just 10) (0.0::Double) [])
putStrLn (showEFloat (Just 0) (2.3::Double) [])
putStrLn (showEFloat Nothing (0.0::Double) [])
putStrLn (showEFloat Nothing (3::Float) [])
putStrLn (showEFloat Nothing (0.5::Float) [])
putStrLn (show (floatToDigits 10 (0.0::Double)))
putStrLn (showFFloat (Just 7) (1.82173691287639817263897126389712638972163e-300::Float) [])
putStrLn (showGFloat (Just 7) (1.82173691287639817263897126389712638972163e-300::Float) [])
main = do
let dbls = map (shEFloat (Just 7)) doubles
++ map (shEFloat (Just 0)) doubles
++ map (shEFloat Nothing) doubles
++ map (shFFloat (Just 7)) doubles
++ map (shFFloat (Just 0)) doubles
++ map (shFFloat Nothing) doubles
++ map (shGFloat (Just 7)) doubles
++ map (shGFloat (Just 0)) doubles
++ map (shGFloat Nothing) doubles
flts = map (shEFloat (Just 7)) floats
++ map (shEFloat (Just 0)) floats
++ map (shEFloat Nothing) floats
++ map (shFFloat (Just 7)) floats
++ map (shFFloat (Just 0)) floats
++ map (shFFloat Nothing) floats
++ map (shGFloat (Just 7)) floats
++ map (shGFloat (Just 0)) floats
++ map (shGFloat Nothing) floats
putStrLn (unlines dbls)
putStrLn (unlines flts)
print (map read dbls :: [Double])
print (map read flts :: [Double])
shEFloat p f = showEFloat p f ""
shFFloat p f = showFFloat p f ""
shGFloat p f = showGFloat p f ""
doubles :: [ Double ]
doubles = [ 0.0
, 420
, 42
, 4.2
, 0.42
, 0.042
, 1.82173691287639817263897126389712638972163
, 1.82173691287639817263897126389712638972163e-300
]
floats :: [ Float ]
floats = [ 0.0
, 420
, 42
, 4.2
, 0.42
, 0.042
, 1.82173691287639817263897126389712638972163
, 1.82173691287639817263897126389712638972163e-300
]
0.0000000e0
4.2000000e2
4.2000000e1
4.2000000e0
4.2000000e-1
4.2000000e-2
1.8217369e0
1.8217369e-300
0.0e0
4.2e2
4.2e1
4.2e0
4.2e-1
4.2e-2
1.8e0
1.8e-300
0.0e0
4.2e2
4.2e1
4.2e0
4.2e-1
4.2e-2
1.8217369128763983e0
1.821736912876398e-300
0.0000000
420.0000000
42.0000000
4.2000000
0.4200000
0.0420000
1.8217369
0.0000000
0
420
42
4
0
0
2
0
0.0
420.0
42.0
4.2
0.42
0.042
1.8217369128763983
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001821736912876398
0.0000000
420.0000000
42.0000000
4.2000000
0.4200000
4.2000000e-2
1.8217369
1.8217369e-300
0
420
42
4
0
4.2e-2
2
1.8e-300
0.0
420.0
42.0
4.2
0.42
4.2e-2
1.8217369128763983
1.821736912876398e-300
0.0000000e0
0.0000000000e0
2.3e0
4.2000000e2
4.2000000e1
4.2000000e0
4.2000000e-1
4.2000000e-2
1.8217369e0
0.0000000e0
0.0e0
4.2e2
4.2e1
4.2e0
4.2e-1
4.2e-2
1.8e0
0.0e0
3.0e0
5.0e-1
([0],0)
0.0e0
4.2e2
4.2e1
4.2e0
4.2e-1
4.2e-2
1.8217369e0
0.0e0
0.0000000
420.0000000
42.0000000
4.2000000
0.4200000
0.0420000
1.8217369
0.0000000
0
420
42
4
0
0
2
0
0.0
420.0
42.0
4.2
0.42
0.042
1.8217369
0.0
0.0000000
420.0000000
42.0000000
4.2000000
0.4200000
4.2000000e-2
1.8217369
0.0000000
0
420
42
4
0
4.2e-2
2
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,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,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]
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