From 0d7354ee32c979ccd36ca2544376d98a0a3ee97d Mon Sep 17 00:00:00 2001 From: sof Date: Thu, 20 Mar 1997 17:38:23 +0000 Subject: [PATCH] [project @ 1997-03-20 17:38:23 by sof] Improved showFloat (catches NaN and Inf) --- ghc/lib/ghc/PrelNum.lhs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ghc/lib/ghc/PrelNum.lhs b/ghc/lib/ghc/PrelNum.lhs index cadad79..e21bc94 100644 --- a/ghc/lib/ghc/PrelNum.lhs +++ b/ghc/lib/ghc/PrelNum.lhs @@ -941,6 +941,13 @@ point type to obtain the same results. {-# GENERATE_SPECS showFloat a{Double#,Double} #-} showFloat:: (RealFloat a) => a -> ShowS showFloat x = + if isNaN x then showString "NaN" + else if isInfinite x then + ( if x < 0 then showString "-" else id) . showString "Infinite" + else if x < 0 || isNegativeZero x then showChar '-' . showFloat' (-x) else showFloat' x + +showFloat' :: (RealFloat a) => a -> ShowS +showFloat' x = if x == 0 then showString ("0." ++ take (m-1) zeros) else if e >= m-1 || e < 0 then showSci else showFix where -- 1.7.10.4