--- /dev/null
+module Main(main) where
+
+import Numeric
+
+main = print ((fromRat (132874 % 23849))::Double)
--- /dev/null
+5.571470501907837
--- /dev/null
+-- Testing showInt, lightly.
+
+module Main(main) where
+
+import Numeric
+
+main =
+ do
+ putStrLn (showInt (343023920121::Integer) [])
+ putStrLn (showInt (3430239::Int) [])
+ putStrLn (showInt (1212 :: Int) [])
+ putStrLn (showInt (591125662431 `div` (517::Int)) [])
+ -- showInt just works over naturals, wrap it up inside
+ -- a use of Numeric.showSigned to show negative nums.
+ putStrLn (showSigned (showInt) 0 (-111::Int) [])
+ putStrLn (showInt (232189458241::Integer) [])
+
--- /dev/null
+343023920121
+3430239
+1212
+1097986
+-111
+232189458241
--- /dev/null
+-- Testing readInt, lightly.
+--
+module Main(main) where
+
+import Numeric
+import Char
+
+main =
+ let
+ rd :: ReadS Integer
+ rd = readInt 10 (isDigit) (digitToInt)
+ in
+ do
+ print (rd (show (343023920121::Integer)))
+ print (rd (show (3430239::Int)))
+ print (rd (show (1212 :: Int)))
+ print (rd (show (591125662431 `div` (517::Int))))
+ print (rd (show (-111::Int)))
+ print (rd (show (232189458241::Integer)))
+
--- /dev/null
+[(343023920121, "")]
+[(3430239, "")]
+[(1212, "")]
+[(1097986, "")]
+[]
+[(232189458241, "")]
--- /dev/null
+-- Exercising Numeric.readSigned a bit
+--
+module Main(main) where
+
+import Numeric
+import Char
+
+main =
+ let
+ rd :: ReadS Integer
+ rd = readSigned (readInt 10 (isDigit) (digitToInt))
+ in
+ do
+ print (rd (show (343023920121::Integer)))
+ print (rd (show (3430239::Int)))
+ print (rd (show (-0 :: Int)))
+ print (rd (show (591125662431 `div` (517::Int))))
+ print (rd (show (-111::Int)))
+ print (rd (show (232189458241::Integer)))
+
--- /dev/null
+[(343023920121, "")]
+[(3430239, "")]
+[(0, "")]
+[(1097986, "")]
+[(-111, "")]
+[(232189458241, "")]
--- /dev/null
+-- Exercising Numeric.readSigned a bit
+--
+module Main(main) where
+
+import Numeric
+
+main =
+ let
+ ls = ["3489348394032498320438240938403","0","-1","1","34323","2L","012","0x23","3243ab"]
+ present str f ls =
+ sequence (map (\ v -> putStr ('\n':str ++
+ ' ': v ++
+ " = " ++
+ (show (f v)))) ls)
+ in
+ do
+ present "(readDec::ReadS Integer)" (readDec::ReadS Integer) ls
+ present "(readDec::ReadS Int)" (readDec::ReadS Int) ls
+ present "(readOct::ReadS Integer)" (readOct::ReadS Integer) ls
+ present "(readOct::ReadS Int)" (readOct::ReadS Int) ls
+ present "(readHex::ReadS Integer)" (readHex::ReadS Integer) ls
+ present "(readHex::ReadS Int)" (readHex::ReadS Int) ls
+ putStrLn ""
--- /dev/null
+-- Exercising the showing of positive numbers at various bases.
+--
+module Main(main) where
+
+import Numeric
+import Char
+import NumExts
+
+--showDec :: Integral a => a -> ShowS
+showDec = showInt
+
+{-
+--showBinary :: Integral a => a -> ShowS
+showBinary n r =
+ showString "0b" $
+ showIntAtBase 2 (toChr) n r
+ where toChr d = chr (ord '0' + fromIntegral d)
+-}
+
+main =
+ do
+ print (map (\ x -> showOct x []) [1..32])
+ print (map (\ x -> showDec x []) [1..32])
+ print (map (\ x -> showHex x []) [1..32])
+-- print (map (\ x -> showBinary x []) [1..32])
+ putStrLn (showOct (241324784::Int) [])
+ putStrLn (showDec (241324784::Int) [])
+ putStrLn (showHex (241324784::Int) [])
+--- putStrLn (showBinary (241324784::Int) [])
--- /dev/null
+["0o1", "0o2", "0o3", "0o4", "0o5", "0o6", "0o7", "0o10", "0o11", "0o12", "0o13", "0o14", "0o15", "0o16", "0o17", "0o20", "0o21", "0o22", "0o23", "0o24", "0o25", "0o26", "0o27", "0o30", "0o31", "0o32", "0o33", "0o34", "0o35", "0o36", "0o37", "0o40"]
+["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"]
+["0x1", "0x2", "0x3", "0x4", "0x5", "0x6", "0x7", "0x8", "0x9", "0xa", "0xb", "0xc", "0xd", "0xe", "0xf", "0x10", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18", "0x19", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f", "0x20"]
+["0b1", "0b10", "0b11", "0b100", "0b101", "0b110", "0b111", "0b1000", "0b1001", "0b1010", "0b1011", "0b1100", "0b1101", "0b1110", "0b1111", "0b10000", "0b10001", "0b10010", "0b10011", "0b10100", "0b10101", "0b10110", "0b10111", "0b11000", "0b11001", "0b11010", "0b11011", "0b11100", "0b11101", "0b11110", "0b11111", "0b100000"]
+0o1630451360
+241324784
+0xe6252f0
+0b1110011000100101001011110000
--- /dev/null
+-- Exercising the reading of positive numbers at various bases.
+--
+module Main(main) where
+
+import Numeric
+
+main =
+ do
+ putStrLn (show (readOct "00000111"))
+ putStrLn (show (readDec "00000111"))
+ putStrLn (show (readHex "00000111"))
+ putStrLn (show (readOct "-24"))
+ putStrLn (show (readDec "-24"))
+ putStrLn (show (readHex "-24"))
+ putStrLn (show ((readOct ::ReadS Integer) "3248784372843778438743"))
+ putStrLn (show ((readDec ::ReadS Integer) "3248784372843778438743"))
+ putStrLn (show ((readHex ::ReadS Integer) "3248784372843778438743"))
--- /dev/null
+"[(73, \"\")]"
+"[(111, \"\")]"
+"[(273, \"\")]"
+"[]"
+"[]"
+"[]"
+"[(212, \"8784372843778438743\")]"
+"[(3248784372843778438743, \"\")]"
+"[(60788519836879239998834499, \"\")]"
--- /dev/null
+-- showing 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) [])
+