Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/Numeric/ReadFloat.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Numeric(readFloat) where

--import RatioCon
import ReadDec
import LexDigits
--import Fractional_Ratio
import Ratio

readFloat:: (RealFrac a) => ReadS a

readFloat r = [(fromRational ((n%1)*10^^(k-d)), t) | (n,d,s) <- readFix r,
						     (k,t)   <- readExp s]  ++
              [ (0/0, t) | ("NaN",t)      <- lex r] ++
              [ (1/0, t) | ("Infinity",t) <- lex r]
              where readFix r = [(read (ds++ds'), length ds', t)
					| (ds,s)  <- lexDigits r,
					  (ds',t) <- lexDot s ]

		    lexDot ('.':s)   = lexDigits s
		    lexDot s         = [("",s)]

		    readExp (e:s) | e `elem` "eE" = readExp' s
                    readExp s			  = [(0,s)]

                    readExp' ('-':s) = [(negate k,t) | (k,t) <- readDec s]
                    readExp' ('+':s) = readDec s
                    readExp' s	     = readDec s


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.