[Haskell-cafe] haskell question
IBRAHIM MOSHAYA
waterblue_ism at hotmail.com
Fri Feb 17 08:36:33 EST 2006
please can you help me with this function:
Significant Figures
I need to write a function to return a given number (1st argument) to a
given number of significant figures
(2nd argument). The function should be called sigFig and have a type
signature of the form:
sigFig :: (???) => a -> Int -> a
For instance:
*Main> sigFig 123.456 2
120.0
*Main> sigFig 123.456 4
123.5
*Main> sigFig 0.987 2
0.99
*Main> sigFig 0.432 2
0.43
The type variable a will need to be constrained, but you should aim for the
most general implementation you
can (replacing ??? above with the appropriate constraint(s)). You may make
free use of Prelude functions.
Referring to [Jon03] you may wish to consider the use of functions /
operators including:
/, div, mod, ^, ^^, **, round, fromIntegral, realToFrac
thanks alot
More information about the Haskell-Cafe
mailing list