From a8925fd8abb400765c6acf0a33485b8b3158750d Mon Sep 17 00:00:00 2001 From: hellerve Date: Sat, 20 May 2017 10:16:28 -0400 Subject: [PATCH] types: drop in replacement of double to 90 decimal bigfloat --- bc.cabal | 2 +- src/BC/Parse.hs | 6 ++++-- src/BC/Types.hs | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bc.cabal b/bc.cabal index 47f165b..783ba33 100644 --- a/bc.cabal +++ b/bc.cabal @@ -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 diff --git a/src/BC/Parse.hs b/src/BC/Parse.hs index 726c84b..cffdac0 100644 --- a/src/BC/Parse.hs +++ b/src/BC/Parse.hs @@ -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 diff --git a/src/BC/Types.hs b/src/BC/Types.hs index f318001..2b289c6 100644 --- a/src/BC/Types.hs +++ b/src/BC/Types.hs @@ -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