Skip to content
Snippets Groups Projects
Commit 571f57b0 authored by sof's avatar sof
Browse files

[project @ 1999-01-19 09:55:05 by sof]

Added showBin (binary nums - no, the 'old' showBin & friends hasn't been resurrected)
+ showIntAtBase to export list:

   showBin       :: (Integral a) => a -> ShowS
   showIntAtBase :: Integral a
	         => a            -- base
	         -> (a -> Char)  -- digit to char
	         -> a            -- number to show.
	         -> ShowS
parent 99419fa2
No related merge requests found
...@@ -10,8 +10,17 @@ module NumExts ...@@ -10,8 +10,17 @@ module NumExts
( (
doubleToFloat -- :: Double -> Float doubleToFloat -- :: Double -> Float
, floatToDouble -- :: Double -> Float , floatToDouble -- :: Double -> Float
, showHex -- :: Integral a => a -> ShowS , showHex -- :: Integral a => a -> ShowS
, showOct -- :: Integral a => a -> ShowS , showOct -- :: Integral a => a -> ShowS
, showBin -- :: Integral a => a -> ShowS
-- general purpose number->string converter.
, showIntAtBase -- :: Integral a
-- => a -- base
-- -> (a -> Char) -- digit to char
-- -> a -- number to show.
-- -> ShowS
) where ) where
import Char (ord, chr) import Char (ord, chr)
...@@ -77,4 +86,10 @@ showOct n r = ...@@ -77,4 +86,10 @@ showOct n r =
showString "0o" $ showString "0o" $
showIntAtBase 8 (toChrOct) n r showIntAtBase 8 (toChrOct) n r
where toChrOct d = chr (ord_0 + fromIntegral d) where toChrOct d = chr (ord_0 + fromIntegral d)
showBin :: Integral a => a -> ShowS
showBin n r =
showString "0b" $
showIntAtBase 2 (toChrOct) n r
where toChrOct d = chr (ord_0 + fromIntegral d)
\end{code} \end{code}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment