Permalink
Browse files

Add a shortest function.

  • Loading branch information...
bos committed Jul 24, 2011
1 parent c9a307d commit 2c7f55854dce6483b8da36001635c4490c5ef1e5
Showing with 8 additions and 0 deletions.
  1. +8 −0 Data/Text/Format.hs
View
@@ -32,6 +32,7 @@ module Data.Text.Format
, expt
, fixed
, prec
+ , shortest
) where
import Control.Monad.IO.Class (MonadIO(liftIO))
@@ -132,6 +133,13 @@ expt decs = B.build . C.toExponential decs . realToFrac
{-# RULES "expt/Double"
forall d x. expt d (x::Double) = B.build (C.toExponential d x) #-}
+-- | Render a floating point number using the smallest number of
+-- digits that correctly represent it.
+shortest :: (Real a) => a -> Builder
+shortest = B.build . C.toShortest . realToFrac
+{-# RULES "shortest/Double"
+ forall x. shortest (x::Double) = B.build (C.toShortest x) #-}
+
-- | Render an integer using hexadecimal notation. (No leading "0x"
-- is added.)
hex :: Integral a => a -> Builder

0 comments on commit 2c7f558

Please sign in to comment.