# [Haskell] for large x, log (x::Integer) :: Double

Hal Daume III hdaume at ISI.EDU
Wed Jun 30 09:47:49 EDT 2004

```i'm looking for an accurate way to take the log of a very large integer,
for example:

let x :: Integer = 1301427272151881160612765560226881966218101403436917787184856303672382623256898455416763978959067300249652773943715743032733292602624834984761739233232794619193611954735720284761058146899246611113236700853600891798968920775344491685185906922596026543915321367577774522912315930144523472702386240645993859368230855941019371447058664115974032571881072431604651385520393674840678811793554266595013773947434115579588912967969680150473258236727830867832149867100437142705476716669039640252677955201589378051836112800268367331455296715904387732836350613539218249950829555418397197909288345303407194983545308212828662999623279222913080214196287140117582811769188486693208227570257136851945943408206281672555558289460256867016896063334140640075708083581866297494610834545554864846306383014549439540479675828018496049574066533167553894586573246931377586176000

this # is approximately 10^850.

not surprisingly, if i do:

log (fromIntegral x) :: Double

i get "Infinity".

i can think of several ways to try to combat this: (1) divide x by
something large (10^850) and then take the log of the integer part
(requires finding that x ~ 10^850 by some search method); (2) multiply x
by something large (10^10) and then take the log of this *as an Integer*
and then convert that to a double.

has anyone encountered this problem before?  surely there must be a "good
way" to do this...

- hal

--
Hal Daume III                                   | hdaume at isi.edu
"Arrest this man, he talks in maths."           | www.isi.edu/~hdaume

```