0

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?

Lukas Klizas
  • 175
  • 12
  • possible duplicate of [High precision floating point numbers in Haskell?](http://stackoverflow.com/questions/16878251/high-precision-floating-point-numbers-in-haskell) – Mephy May 12 '15 at 23:55
  • Talking about floating point and "arbitrary precision" is just confusing people here—those are irrelevant. – dfeuer May 14 '15 at 14:24

2 Answers2

3

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.

Cactus
  • 27,075
  • 9
  • 69
  • 149
Cubic
  • 14,902
  • 5
  • 47
  • 92
  • I would change that to "exact rationals". – dfeuer May 14 '15 at 14:25
  • @dfeuer What would be the difference between an exact rational and a not-exact rational? – Cubic May 14 '15 at 14:34
  • What is the "precision" of a rational? To a Scheme programmer, the notion of "inexact rational" would actually make perfect sense, and would mean a rational that was approximating something else; that concept does not really exist in Haskell. – dfeuer May 14 '15 at 14:37
0
> 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
dfeuer
  • 48,079
  • 5
  • 63
  • 167