types: drop in replacement of double to 90 decimal bigfloat

This commit is contained in:
2017-05-20 10:16:28 -04:00
parent 119d4bfbe1
commit a8925fd8ab
3 changed files with 7 additions and 4 deletions

View File

@@ -14,6 +14,6 @@ cabal-version: >=1.10
executable bc
main-is: Main.hs
hs-source-dirs: src/
build-depends: base >=4.9 && <4.10, directory, hashmap, parsec, unix
build-depends: base >=4.9 && <4.10, directory, hashmap, numbers, parsec, unix
hs-source-dirs: src
default-language: Haskell2010

View File

@@ -32,8 +32,10 @@ float = do
_ <- P.string "."
y <- P.many1 P.digit
case neg of
Just "-" -> (return . BNum . BFloat . read) ("-" ++ x ++ "." ++ y)
_ -> (return . BNum . BFloat . read) (x ++ "." ++ y)
Just "-" -> return $ construct ("-" ++ x ++ "." ++ y)
_ -> return $ construct (x ++ "." ++ y)
-- do a little dance
where construct str = BNum $ BFloat $ fromRational $ realToFrac $ (read str::Double)
integer :: P.Parser Value

View File

@@ -1,6 +1,7 @@
module BC.Types where
import Data.List (intercalate)
import Data.Number.BigFloat
data Value = BNum Number
| BBool Bool
@@ -36,7 +37,7 @@ instance Show Value where
-- sorry, this is a little hacky
data Number = BInt Integer
| BFloat Double
| BFloat (BigFloat (PrecPlus20 (PrecPlus20 Prec50)))
deriving (Ord, Eq)
instance Show Number where
show (BInt i) = show i