[Haskell-cafe] Re: Float instance of Data.Bits
nbowler at elliptictech.com
Mon Jul 12 09:35:14 EDT 2010
On 22:02 Sat 10 Jul , Sam Martin wrote:
> > Note that the Haskell report does not require IEEE 754 binary encodings.
> > In fact, it permits 'Float' to be a decimal floating point type.
> True. Although I don't really understand why? Or rather, I don't
> understand why it can't be at least slightly more specific and at
> least state that Float is a 32-bit floating point value and Double is
> a 64-bit floating point value. The exact handling of various
> exceptions and denormals tends to vary across hardware, but this at
> least allows you to get at the representation.
Because this precludes efficient Haskell implementations on platforms
which do not support these formats in hardware (but might support other
formats). Also, there are other problems if the Float and Double types
do not match the corresponding types of the system's C implementation.
> I realise it'll be platform-specific (assuming isIEEE returns false),
> but then so is the behaviour of your code if you don't require IEEE
IEEE 754 defines five "basic" floating point formats:
binary32: 24 bits precision and a maximum exponent of 127.
binary64: 53 bits precision and a maximum exponent of 1023.
binary128: 113 bits precision and a maximum exponent of 16383.
decimal64: 16 digits precision and a maximum exponent of 384.
decimal128: 34 digits precision and a maximum exponent of 6144.
Each of these formats has a specific binary representation (with the
lovely storage hacks we all know and love). Additionally, there are two
more interchange formats which are not intended for use in arithmetic:
binary16: 11 bits precision and a maximum exponent of 15.
decimal32: 7 digits precision and a maximum exponent of 96.
Furthermore, there are so-called "Extended" and "Extensible" formats,
which satisfy certain requirements of the standard, but are permitted
to have any encoding whatsoever.
A Haskell implementation tuned for development of financial applications
would likely define Float as the decimal64 format, and Double as the
decimal128 format. isIEEE would return True since these types and
related operations conform to the IEEE floating point standard.
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
More information about the Haskell-Cafe