i'm looking for an accurate way to take the log of a very large integer,
This may not help, but just in case... there is an effective (approximate) algorithm for computing a log-gamma function, documented in "Numerical Recipies" by Press/Flannery/Teukolsky/Vetterling.
If you want more info, I have an implementation in Mathematica somewhere, and could dig out a more specific reference.
The alternative way I'd consider involves building a power series of (2^(2^i)) and performing a compare-and-divide-and-sum so that you get n and x in 2^n*x, for x in the range (0.0..1.0) (or any other range that you may choose).
#g --
At 06:47 30/06/04 -0700, Hal Daume III wrote:
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 | [EMAIL PROTECTED] "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
_______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
_______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell