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

Greg Buchholz haskell at sleepingsquirrel.org
Wed Jun 30 18:07:00 EDT 2004


-- Inspired from Mr. Howard Oakley.  Might not qualify as "good",
-- but with this function I get log10(x)=849.114419903382

main = do
          print(show(log10(x)))

x = 1301427272151881160612765560226881966218101403436917787184856303672382623256898455416763978959067300249652773943715743032733292602624834984761739233232794619193611954735720284761058146899246611113236700853600891798968920775344491685185906922596026543915321367577774522912315930144523472702386240645993859368230855941019371447058664115974032571881072431604651385520393674840678811793554266595013773947434115579588912967969680150473258236727830867832149867100437142705476716669039640252677955201589378051836112800268367331455296715904387732836350613539218249950829555418397197909288345303407194983545308212828662999623279222913080214196287140117582811769188486693208227570257136851945943408206281672555558289460256867016896063334140640075708083581866297494610834545554864846306383014549439540479675828018496049574066533167553894586573246931377586176000

log10 :: Integer -> Double
log10 n = let i = length(show(n)) - 1
              t = take 12 (show(n))
              r = read(t)
              f = r / 10 ^ (length(t) - 1)
          in fromIntegral(i) + log(f)/log(10)

--Greg Buchholz


More information about the Haskell mailing list