Commits

Bryan O'Sullivan committed d237f4d

Add a shortest function.

  • Participants
  • Parent commits 7b998af

Comments (0)

Files changed (1)

File Data/Text/Format.hs

     , expt
     , fixed
     , prec
+    , shortest
     ) where
 
 import Control.Monad.IO.Class (MonadIO(liftIO))
 {-# 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