Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use extended precision (80-bit) floating point arithmetic in GHC/Haskell?

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?

like image 472
Petr Avatar asked May 28 '13 17:05

Petr


People also ask

How many bits are used in extended precision floating-point format respectively?

Standard precision format contains a 24-bit two's complement significand while extended precision utilizes a 32-bit two's complement significand.

How many bits are in high precision floating point decimal values?

The most commonly used floating point standard is the IEEE standard. According to this standard, floating point numbers are represented with 32 bits (single precision) or 64 bits (double precision).

What is extended precision format?

Extended-precision numbers are composed of two double-precision numbers with different magnitudes that do not overlap (except when the number is zero or close to zero). That is, the binary exponents differ by at least the number of fraction bits in a REAL(8).


1 Answers

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.

like image 135
Mekeor Melire Avatar answered Sep 23 '22 20:09

Mekeor Melire