15

The standard Haskell's Double uses the standard double-precision arithmetic:

data Double Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.

Does GHC/Haskell offer somewhere also the extended precision (80-bit) floating point numbers, perhaps using some external library?

Petr
  • 62,528
  • 13
  • 153
  • 317

1 Answers1

14

As chuff has pointed out, you might want to take a look a the numbers package on hackage. You can install it with cabal install numbers. Here is an example:

import Data.Number.CReal -- from numbers

main :: IO ()
main = putStrLn (showCReal 100 (sqrt 2))

-- output: 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727

As the documentation states, showCReal returns a string showing a given number of type CReal with the given number of decimals.

Mekeor Melire
  • 502
  • 5
  • 15
  • 1
    I guess I was assuming I was talking to a beginner... anyways. ;) – Mekeor Melire May 28 '13 at 22:45
  • 6
    I don't think he's looking for arbitrary precision, just a way to take advantage of the 80-bit floating point capabilities of most popular processors. – hammar May 28 '13 at 22:48
  • 2
    Yes, thanks for the pointer to _numbers_, it might come in handy, but right now I'm looking just for the 80-bit floating point arithmetic. – Petr May 29 '13 at 09:41