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
%
......@@ -552,23 +552,22 @@ point type to obtain the same results.
ReadS Double,
ReadS Float #-}
readFloat :: (RealFloat a) => ReadS a
readFloat r = do
(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 )) ++
readFloat r =
(do
(x,t) <- readRational r
return (fromRational x,t) ) ++
(do
("NaN",t) <- lex r
return (0/0,t) ) ++
(do
("Infinity",t) <- lex r
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
readFix r = do
(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