Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[project @ 1998-04-30 19:50:18 by sof]

showInt is only supposed to work on non-negative numbers
  • Loading branch information...
commit 009527af27c8ee36a59db4d451e7c7a9896cb1da 1 parent 4c177fb
sof authored
Showing with 11 additions and 6 deletions.
  1. +11 −6 ghc/lib/std/Numeric.lhs
View
17 ghc/lib/std/Numeric.lhs
@@ -35,6 +35,7 @@ import PrelMaybe
import PrelArr
import PrelNum
import PrelRead
+import PrelErr ( error )
\end{code}
@@ -73,13 +74,17 @@ lexDigits :: ReadS String
\begin{code}
showInt :: Integral a => a -> ShowS
showInt n r
- = case quotRem n 10 of { (n', d) ->
- case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary
- let
+ | n < 0 = error "Numeric.showInt: can't show negative numbers"
+ | otherwise = go n r
+ where
+ go n r =
+ case quotRem n 10 of { (n', d) ->
+ case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary
+ let
r' = C# c# : r
- in
- if n' == 0 then r' else showInt n' r'
- }}
+ in
+ if n' == 0 then r' else go n' r'
+ }}
\end{code}
Controlling the format and precision of floats. The code that
Please sign in to comment.
Something went wrong with that request. Please try again.