Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gesh
GHC
Commits
ab5a9b60
Commit
ab5a9b60
authored
27 years ago
by
sof
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1997-05-18 04:04:30 by sof]
parent
fae5e3bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/lib/required/Numeric.lhs
+130
-0
130 additions, 0 deletions
ghc/lib/required/Numeric.lhs
with
130 additions
and
0 deletions
ghc/lib/required/Numeric.lhs
0 → 100644
+
130
−
0
View file @
ab5a9b60
%
% (c) The AQUA Project, Glasgow University, 1997
%
\section[Numeric]{Numeric interface}
Odds and ends, mostly functions for reading and showing
\tr{RealFloat}-like kind of values.
\begin{code}
{-# OPTIONS -fno-implicit-prelude #-}
module Numeric
(
fromRat,
showSigned,
readSigned,
showInt,
readInt,
readDec, readOct, readHex,
showDec, showOct, showHex,
showEFloat,
showFFloat,
showGFloat,
showFloat,
readFloat,
floatToDigits,
lexDigits
) where
import PrelBase
import ArrBase
import PrelNum
import PrelRead
\end{code}
%*********************************************************
%* *
\subsection{Signatures}
%* *
%*********************************************************
Interface on offer:
\begin{pseudocode}
fromRat :: (RealFloat a) => Rational -> a
showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS
readSigned :: (Real a) => ReadS a -> ReadS a
showInt :: Integral a => a -> ShowS
readInt :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
readDec :: (Integral a) => ReadS a
readOct :: (Integral a) => ReadS a
readHex :: (Integral a) => ReadS a
showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showFloat :: (RealFloat a) => a -> ShowS
readFloat :: (RealFloat a) => ReadS a
floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)
lexDigits :: ReadS String
\end{pseudocode}
\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
r' = C# c# : r
in
if n' == 0 then r' else showInt n' r'
}}
showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS
showIntAtBase base toChr n r
= case quotRem n base of { (n', d) ->
case toChr d of { C# c# -> -- stricter than necessary
let
r' = C# c# : r
in
if n' == 0 then r' else showIntAtBase base toChr n' r'
}}
showDec :: Integral a => a -> ShowS
showDec n r =
showIntAtBase 10
(\ d -> chr (ord_0 + fromIntegral d))
n r
showHex :: Integral a => a -> ShowS
showHex n r =
showString "0x" $
showIntAtBase 16 (toChrHex) n r
where
toChrHex d =
if d < 10 then
chr (ord_0 + fromIntegral d)
else
chr (ord 'a' + fromIntegral (d - 10))
showOct :: Integral a => a -> ShowS
showOct n r =
showString "0o" $
showIntAtBase 8 (toChrOct) n r
where toChrOct d = chr (ord_0 + fromIntegral d)
\end{code}
\begin{code}
showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
showEFloat d x = showString (formatRealFloat FFExponent d x)
showFFloat d x = showString (formatRealFloat FFFixed d x)
showGFloat d x = showString (formatRealFloat FFGeneric d x)
\end{code}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment