Haskell-Decimal icon indicating copy to clipboard operation
Haskell-Decimal copied to clipboard

Prelude.read: no parse error for numbers with more than 255 decimal places

Open ejserna opened this issue 7 years ago • 2 comments

Doing a read of a number with more than 255 decimal places i.e.

read("12.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333") :: Decimal

(256 decimal places)

Causes the following error:

*** Exception: Prelude.read: no parse

ejserna avatar Feb 13 '18 02:02 ejserna

Decimal uses a Word8 (i.e. 8 bits) to store the exponent, so this is the Right Thing. A note in the documentation might be a good idea though.

PaulJohnson avatar Feb 13 '18 08:02 PaulJohnson

Maybe we could do a function before doing readDecimalP. Something like

get255Decimals :: String  -> String
get255Decimals ('.' : xs) = "." ++ (take 255 xs) 
get255Decimals (x : xs) = [x] ++ (get255Decimals xs)

could do the job.

ejserna avatar Feb 18 '18 07:02 ejserna