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

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


module Numeric where

import Char (intToDigit)

showIntAtBase :: Integral a => a -> (Int->Char) -> a -> ShowS
showIntAtBase base intToDig n r
  | n < 0   = error "Numeric.showIntAtBase: can't show negative numbers"
  | otherwise =
      let (n',d) = quotRem n base
          r'     = intToDig (fromIntegral d) : r
      in if n' == 0 then r' else showIntAtBase base intToDig n' r'

showHex, showOct, showBin :: Integral a => a -> ShowS
showHex = showIntAtBase 16 intToDigit
showOct = showIntAtBase 8 intToDigit
showBin = showIntAtBase 2 intToDigit

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.