types: drop in replacement of double to 90 decimal bigfloat
This commit is contained in:
2
bc.cabal
2
bc.cabal
@@ -14,6 +14,6 @@ cabal-version: >=1.10
|
|||||||
executable bc
|
executable bc
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
hs-source-dirs: src/
|
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
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
@@ -32,8 +32,10 @@ float = do
|
|||||||
_ <- P.string "."
|
_ <- P.string "."
|
||||||
y <- P.many1 P.digit
|
y <- P.many1 P.digit
|
||||||
case neg of
|
case neg of
|
||||||
Just "-" -> (return . BNum . BFloat . read) ("-" ++ x ++ "." ++ y)
|
Just "-" -> return $ construct ("-" ++ x ++ "." ++ y)
|
||||||
_ -> (return . BNum . BFloat . read) (x ++ "." ++ y)
|
_ -> return $ construct (x ++ "." ++ y)
|
||||||
|
-- do a little dance
|
||||||
|
where construct str = BNum $ BFloat $ fromRational $ realToFrac $ (read str::Double)
|
||||||
|
|
||||||
|
|
||||||
integer :: P.Parser Value
|
integer :: P.Parser Value
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
module BC.Types where
|
module BC.Types where
|
||||||
|
|
||||||
import Data.List (intercalate)
|
import Data.List (intercalate)
|
||||||
|
import Data.Number.BigFloat
|
||||||
|
|
||||||
data Value = BNum Number
|
data Value = BNum Number
|
||||||
| BBool Bool
|
| BBool Bool
|
||||||
@@ -36,7 +37,7 @@ instance Show Value where
|
|||||||
|
|
||||||
-- sorry, this is a little hacky
|
-- sorry, this is a little hacky
|
||||||
data Number = BInt Integer
|
data Number = BInt Integer
|
||||||
| BFloat Double
|
| BFloat (BigFloat (PrecPlus20 (PrecPlus20 Prec50)))
|
||||||
deriving (Ord, Eq)
|
deriving (Ord, Eq)
|
||||||
instance Show Number where
|
instance Show Number where
|
||||||
show (BInt i) = show i
|
show (BInt i) = show i
|
||||||
|
Reference in New Issue
Block a user