Commit 986b581d authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-28 09:55:35 by simonmar]

Fix (read "Infinity") and (read "NaN") for RealFloat types.
parent ab10dec5
% ------------------------------------------------------------------------------ % ------------------------------------------------------------------------------
% $Id: PrelRead.lhs,v 1.20 2001/05/23 09:28:44 simonmar Exp $ % $Id: PrelRead.lhs,v 1.21 2001/08/28 09:55:35 simonmar Exp $
% %
% (c) The University of Glasgow, 1994-2000 % (c) The University of Glasgow, 1994-2000
% %
...@@ -552,23 +552,22 @@ point type to obtain the same results. ...@@ -552,23 +552,22 @@ point type to obtain the same results.
ReadS Double, ReadS Double,
ReadS Float #-} ReadS Float #-}
readFloat :: (RealFloat a) => ReadS a readFloat :: (RealFloat a) => ReadS a
readFloat r = do readFloat r =
(x,t) <- readRational r (do
return (fromRational x,t) (x,t) <- readRational r
return (fromRational x,t) ) ++
readRational :: ReadS Rational -- NB: doesn't handle leading "-"
readRational r =
(do
(n,d,s) <- readFix r
(k,t) <- readExp s
return ((n%1)*10^^(k-d), t )) ++
(do (do
("NaN",t) <- lex r ("NaN",t) <- lex r
return (0/0,t) ) ++ return (0/0,t) ) ++
(do (do
("Infinity",t) <- lex r ("Infinity",t) <- lex r
return (1/0,t) ) return (1/0,t) )
readRational :: ReadS Rational -- NB: doesn't handle leading "-"
readRational r = do
(n,d,s) <- readFix r
(k,t) <- readExp s
return ((n%1)*10^^(k-d), t)
where where
readFix r = do readFix r = do
(ds,s) <- lexDecDigits r (ds,s) <- lexDecDigits r
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment