Lukas Klizas
Lukas Klizas

Reputation: 175

Haskell floating point operation precision

I have to make software to solve this problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=689

Basically, I need to calculate powers of rational numbers, for example 95.123^12 with arbitrary precision.

Is it possible to achieve it with haskell?

Upvotes: 0

Views: 236

Answers (2)

dfeuer
dfeuer

Reputation: 48631

> import Data.Ratio
> 95.123^12 :: Rational
548815620517731830194541899025343415715973535967221869852721 % 1000000000000000000000000000000000000

That % is the fraction bar. You can also use it for input:

> (4%5)^12
16777216 % 244140625

Upvotes: 0

Cubic
Cubic

Reputation: 15703

Arbitrary precision rationals are possible to implement in every language (how easy it is depends, of course). In Haskell there is the Data.Ratio module that gives you arbitrary precision rationals. Note that this isn't the same thing as floating point numbers.

Upvotes: 3

Related Questions