double-conversion-2.0.5.0: Fast conversion between single and double precision floating point and text

Copyright | (c) 2011 MailRank Inc.
License | BSD-style
Maintainer | bos@serpentine.com
Stability | experimental
Portability | GHC
Safe Haskell | None
Language | Haskell2010

Data.Double.Conversion.Convertable

Description

Synopsis

- class (RealFloat a, IsString b) => Convertable a b where
  - toExponential :: Int -> a -> b
  - toPrecision :: Int -> a -> b
  - toFixed :: Int -> a -> b
  - toShortest :: a -> b

# Documentation

class (RealFloat a, IsString b) => Convertable a b where Source #

Type class for floating data types, that can be converted, using double-conversion library

Default instanced convert input to Double and then make Bytestring Builder from it.

list of functions :

toExponential: Compute a representation in exponential format with the requested number of digits after the decimal point. The last emitted digit is rounded. If -1 digits are requested, then the shortest exponential representation is computed.

toPrecision: Compute `precision` leading digits of the given value either in exponential or decimal format. The last computed digit is rounded.

toFixed: Compute a decimal representation with a fixed number of digits after the decimal point. The last emitted digit is rounded.

toShortest: Compute the shortest string of digits that correctly represent the input number.

Conversion to text via Builder (both in the in case of bytestring and text) in case of single number is a bit slower, than to text or bytestring directly. But conversion a large amount of numbers to text via Builder (for example using foldr) is much faster than direct conversion to Text (up to 10-15x).

The same works for bytestrings: conversion, for example, a list of 20000 doubles to bytestring builder and then to bytestring is about 13 times faster than direct conversion of this list to bytestring.

Conversion to text via text builder is a little bit slower, than conversion to bytestring via bytestring builder.

Minimal complete definition

Nothing

Methods

toExponential :: Int -> a -> b Source #

default toExponential :: b ~ Builder => Int -> a -> b Source #

toPrecision :: Int -> a -> b Source #

default toPrecision :: b ~ Builder => Int -> a -> b Source #

toFixed :: Int -> a -> b Source #

default toFixed :: b ~ Builder => Int -> a -> b Source #

toShortest :: a -> b Source #

default toShortest :: b ~ Builder => a -> b Source #

#### Instances

Instances details

Convertable Double Builder Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Double -> Builder Source # toPrecision :: Int -> Double -> Builder Source # toFixed :: Int -> Double -> Builder Source # toShortest :: Double -> Builder Source #
Convertable Double ByteString Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Double -> ByteString Source # toPrecision :: Int -> Double -> ByteString Source # toFixed :: Int -> Double -> ByteString Source # toShortest :: Double -> ByteString Source #
Convertable Double Text Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Double -> Text Source # toPrecision :: Int -> Double -> Text Source # toFixed :: Int -> Double -> Text Source # toShortest :: Double -> Text Source #
Convertable Double Builder Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Double -> Builder Source # toPrecision :: Int -> Double -> Builder Source # toFixed :: Int -> Double -> Builder Source # toShortest :: Double -> Builder Source #
Convertable Float Builder Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Float -> Builder Source # toPrecision :: Int -> Float -> Builder Source # toFixed :: Int -> Float -> Builder Source # toShortest :: Float -> Builder Source #
Convertable Float ByteString Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Float -> ByteString Source # toPrecision :: Int -> Float -> ByteString Source # toFixed :: Int -> Float -> ByteString Source # toShortest :: Float -> ByteString Source #
Convertable Float Text Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Float -> Text Source # toPrecision :: Int -> Float -> Text Source # toFixed :: Int -> Float -> Text Source # toShortest :: Float -> Text Source #
Convertable Float Builder Source # |
Instance details Defined in Data.Double.Conversion.Convertable Methods toExponential :: Int -> Float -> Builder Source # toPrecision :: Int -> Float -> Builder Source # toFixed :: Int -> Float -> Builder Source # toShortest :: Float -> Builder Source #