From 986b581d6d3329accf61f3b295a51d1ccea1adc8 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 28 Aug 2001 09:55:35 +0000 Subject: [PATCH] [project @ 2001-08-28 09:55:35 by simonmar] Fix (read "Infinity") and (read "NaN") for RealFloat types. --- ghc/lib/std/PrelRead.lhs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ghc/lib/std/PrelRead.lhs b/ghc/lib/std/PrelRead.lhs index f8a2636..b91cb96 100644 --- a/ghc/lib/std/PrelRead.lhs +++ b/ghc/lib/std/PrelRead.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $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 -- 1.7.10.4