Fast log approximation algorithm

Posted:
in Genius Bar edited January 2014
Does anyone know of any fast and accurate log approximation algorithms,preferably one that can be iterated to any desired level of accuracy.It only needs to work between the values 0.01 and 1.0.I have one that uses the Taylor series,but it is a little on the long -winded side.Here it is for the curious.By the way any info would be appreciated.



[quote]



# Fairly accurate between 0.01 and 1.0. Greatest error is .00144,at 0.01.



+to approximate-logarithm of-number theNumber(float):

newValue(float).



theNumber -= 1.







newValue = theNumber + (-(theNumber^2)/2) + ((theNumber^3)/3)

+ (-(theNumber^4)/4) + ((theNumber^5)/5)

+ (-(theNumber^6)/6) + ((theNumber^7)/7)

+ (-(theNumber^8)/8) + ((theNumber^9)/9)

+ (-(theNumber^10)/10) + ((theNumber^11)/11)

+ (-(theNumber^12)/12) + ((theNumber^13)/13)

+ (-(theNumber^14)/14) + ((theNumber^15)/15)

+ (-(theNumber^16)/16) + ((theNumber^17)/17)

+ (-(theNumber^18)/18) + ((theNumber^19)/19)

+ (-(theNumber^20)/20) + ((theNumber^21)/21)

+ (-(theNumber^22)/22) + ((theNumber^23)/23)

+ (-(theNumber^24)/24) + ((theNumber^25)/25)

+ (-(theNumber^26)/26) + ((theNumber^27)/27)

+ (-(theNumber^28)/28) + ((theNumber^29)/29)

+ (-(theNumber^30)/30) + ((theNumber^31)/31)

+ (-(theNumber^32)/32) + ((theNumber^33)/33)

+ (-(theNumber^34)/34) + ((theNumber^35)/35)

+ (-(theNumber^36)/36) + ((theNumber^37)/37)

+ (-(theNumber^38)/38) + ((theNumber^39)/39)

+ (-(theNumber^40)/40) + ((theNumber^41)/41)

+ (-(theNumber^42)/42) + ((theNumber^43)/43)

+ (-(theNumber^44)/44) + ((theNumber^45)/45)

+ (-(theNumber^46)/46) + ((theNumber^47)/47)

+ (-(theNumber^48)/48) + ((theNumber^49)/49)

+ (-(theNumber^50)/50) + ((theNumber^51)/51)

+ (-(theNumber^52)/52) + ((theNumber^53)/53)

+ (-(theNumber^54)/54) + ((theNumber^55)/55)

+ (-(theNumber^56)/56) + ((theNumber^57)/57)

+ (-(theNumber^58)/58) + ((theNumber^59)/59)

+ (-(theNumber^60)/60) + ((theNumber^61)/61)

+ (-(theNumber^62)/62) + ((theNumber^63)/63)

+ (-(theNumber^64)/64) + ((theNumber^65)/65)

+ (-(theNumber^66)/66) + ((theNumber^67)/67)

+ (-(theNumber^68)/68) + ((theNumber^69)/69)

+ (-(theNumber^70)/70) + ((theNumber^71)/71)

+ (-(theNumber^72)/72) + ((theNumber^73)/73)

+ (-(theNumber^74)/74) + ((theNumber^75)/75)

+ (-(theNumber^76)/76) + ((theNumber^77)/77)

+ (-(theNumber^78)/78) + ((theNumber^79)/79)

+ (-(theNumber^80)/80) + ((theNumber^81)/81)

+ (-(theNumber^82)/82) + ((theNumber^83)/83)

+ (-(theNumber^84)/84) + ((theNumber^85)/85)

+ (-(theNumber^86)/86) + ((theNumber^87)/87)

+ (-(theNumber^88)/88) + ((theNumber^89)/89)

+ (-(theNumber^90)/90) + ((theNumber^91)/91)

+ (-(theNumber^92)/92) + ((theNumber^93)/93)

+ (-(theNumber^94)/94) + ((theNumber^95)/95)

+ (-(theNumber^96)/96) + ((theNumber^97)/97)

+ (-(theNumber^98)/98) + ((theNumber^99)/99)

+ (-(theNumber^100)/100) + ((theNumber^101)/101)

+ (-(theNumber^102)/102) + ((theNumber^103)/103)

+ (-(theNumber^104)/104) + ((theNumber^105)/105)

+ (-(theNumber^106)/106) + ((theNumber^107)/107)

+ (-(theNumber^108)/108) + ((theNumber^109)/109)

+ (-(theNumber^110)/110) + ((theNumber^111)/111)

+ (-(theNumber^112)/112) + ((theNumber^113)/113)

+ (-(theNumber^114)/114) + ((theNumber^115)/115)

+ (-(theNumber^116)/116) + ((theNumber^117)/117)

+ (-(theNumber^118)/118) + ((theNumber^119)/119)

+ (-(theNumber^120)/120) + ((theNumber^121)/121)

+ (-(theNumber^122)/122) + ((theNumber^123)/123)

+ (-(theNumber^124)/124) + ((theNumber^125)/125)

+ (-(theNumber^126)/126) + ((theNumber^127)/127)

+ (-(theNumber^128)/128) + ((theNumber^129)/129)

+ (-(theNumber^130)/130) + ((theNumber^131)/131)

+ (-(theNumber^132)/132) + ((theNumber^133)/133)

+ (-(theNumber^134)/134) + ((theNumber^135)/135)

+ (-(theNumber^136)/136) + ((theNumber^137)/137)

+ (-(theNumber^138)/138) + ((theNumber^139)/139)

+ (-(theNumber^140)/140) + ((theNumber^141)/141)

+ (-(theNumber^142)/142) + ((theNumber^143)/143)

+ (-(theNumber^144)/144) + ((theNumber^145)/145)

+ (-(theNumber^146)/146) + ((theNumber^147)/147)

+ (-(theNumber^148)/148) + ((theNumber^149)/149)

+ (-(theNumber^150)/150) + ((theNumber^151)/151)

+ (-(theNumber^152)/152) + ((theNumber^153)/153)

+ (-(theNumber^154)/154) + ((theNumber^155)/155)

+ (-(theNumber^156)/156) + ((theNumber^157)/157)

+ (-(theNumber^158)/158) + ((theNumber^159)/159)

+ (-(theNumber^160)/160) + ((theNumber^161)/161)

+ (-(theNumber^162)/162) + ((theNumber^163)/163)

+ (-(theNumber^164)/164) + ((theNumber^165)/165)

+ (-(theNumber^166)/166) + ((theNumber^167)/167)

+ (-(theNumber^168)/168) + ((theNumber^169)/169)

+ (-(theNumber^170)/170) + ((theNumber^171)/171)

+ (-(theNumber^172)/172) + ((theNumber^173)/173)

+ (-(theNumber^174)/174) + ((theNumber^175)/175)

+ (-(theNumber^176)/176) + ((theNumber^177)/177)

+ (-(theNumber^178)/178) + ((theNumber^179)/179)

+ (-(theNumber^180)/180) + ((theNumber^181)/181)

+ (-(theNumber^182)/182) + ((theNumber^183)/183)

+ (-(theNumber^184)/184) + ((theNumber^185)/185)

+ (-(theNumber^186)/186) + ((theNumber^187)/187)

+ (-(theNumber^188)/188) + ((theNumber^189)/189)

+ (-(theNumber^190)/190) + ((theNumber^191)/191)

+ (-(theNumber^192)/192) + ((theNumber^193)/193)

+ (-(theNumber^194)/194) + ((theNumber^195)/195)

+ (-(theNumber^196)/196) + ((theNumber^197)/197)

+ (-(theNumber^198)/198) + ((theNumber^199)/199)

+ (-(theNumber^200)/200) + ((theNumber^201)/201)

+ (-(theNumber^202)/202) + ((theNumber^203)/203)

+ (-(theNumber^204)/204) + ((theNumber^205)/205)

+ (-(theNumber^206)/206) + ((theNumber^207)/207)

+ (-(theNumber^208)/208) + ((theNumber^209)/209)

+ (-(theNumber^210)/210) + ((theNumber^211)/211)

+ (-(theNumber^212)/212) + ((theNumber^213)/213)

+ (-(theNumber^214)/214) + ((theNumber^215)/215)

+ (-(theNumber^216)/216) + ((theNumber^217)/217)

+ (-(theNumber^218)/218) + ((theNumber^219)/219)

+ (-(theNumber^220)/220) + ((theNumber^221)/221)

+ (-(theNumber^222)/222) + ((theNumber^223)/223)

+ (-(theNumber^224)/224) + ((theNumber^225)/225)

+ (-(theNumber^226)/226) + ((theNumber^227)/227)

+ (-(theNumber^228)/228) + ((theNumber^229)/229)

+ (-(theNumber^230)/230) + ((theNumber^231)/231)

+ (-(theNumber^232)/232) + ((theNumber^233)/233)

+ (-(theNumber^234)/234) + ((theNumber^235)/235)

+ (-(theNumber^236)/236) + ((theNumber^237)/237)

+ (-(theNumber^238)/238) + ((theNumber^239)/239)

+ (-(theNumber^240)/240) + ((theNumber^241)/241)

+ (-(theNumber^242)/242) + ((theNumber^243)/243)

+ (-(theNumber^244)/244) + ((theNumber^245)/245)

+ (-(theNumber^246)/246) + ((theNumber^247)/247)

+ (-(theNumber^248)/248) + ((theNumber^249)/249)

+ (-(theNumber^250)/250) + ((theNumber^251)/251)

+ (-(theNumber^252)/252) + ((theNumber^253)/253)

+ (-(theNumber^254)/254) + ((theNumber^255)/255)

+ (-(theNumber^256)/256) + ((theNumber^257)/257)

+ (-(theNumber^258)/258) + ((theNumber^259)/259)

+ (-(theNumber^260)/260) + ((theNumber^261)/261)

+ (-(theNumber^262)/262) + ((theNumber^263)/263)

+ (-(theNumber^264)/264) + ((theNumber^265)/265)

+ (-(theNumber^266)/266) + ((theNumber^267)/267)

+ (-(theNumber^268)/268) + ((theNumber^269)/269)

+ (-(theNumber^270)/270) + ((theNumber^271)/271)

+ (-(theNumber^272)/272) + ((theNumber^273)/273)

+ (-(theNumber^274)/274) + ((theNumber^275)/275)

+ (-(theNumber^276)/276) + ((theNumber^277)/277)

+ (-(theNumber^278)/278) + ((theNumber^279)/279)

+ (-(theNumber^280)/280) + ((theNumber^281)/281)

+ (-(theNumber^282)/282) + ((theNumber^283)/283)

+ (-(theNumber^284)/284) + ((theNumber^285)/285)

+ (-(theNumber^286)/286) + ((theNumber^287)/287)

+ (-(theNumber^288)/288) + ((theNumber^289)/289)

+ (-(theNumber^290)/290) + ((theNumber^291)/291)

+ (-(theNumber^292)/292) + ((theNumber^293)/293)

+ (-(theNumber^294)/294) + ((theNumber^295)/295)

+ (-(theNumber^296)/296) + ((theNumber^297)/297)

+ (-(theNumber^298)/298) + ((theNumber^299)/299)

+ (-(theNumber^300)/300) + ((theNumber^301)/301)

+ (-(theNumber^302)/302) + ((theNumber^303)/303)

+ (-(theNumber^304)/304) + ((theNumber^305)/305)

+ (-(theNumber^306)/306) + ((theNumber^307)/307)

+ (-(theNumber^308)/308) + ((theNumber^309)/309)

+ (-(theNumber^310)/310) + ((theNumber^311)/311)

+ (-(theNumber^312)/312) + ((theNumber^313)/313)

+ (-(theNumber^314)/314) + ((theNumber^315)/315)

+ (-(theNumber^316)/316) + ((theNumber^317)/317)

+ (-(theNumber^318)/318) + ((theNumber^319)/319)

+ (-(theNumber^320)/320) + ((theNumber^321)/321)

+ (-(theNumber^322)/322) + ((theNumber^322)/322)

+ (-(theNumber^324)/324) + ((theNumber^325)/325)

+ (-(theNumber^326)/326) + ((theNumber^327)/327)

+ (-(theNumber^328)/328) + ((theNumber^329)/329)

+ (-(theNumber^330)/330) + ((theNumber^331)/331)

+ (-(theNumber^332)/332) + ((theNumber^333)/333)

+ (-(theNumber^334)/334) + ((theNumber^335)/335)

+ (-(theNumber^336)/336) + ((theNumber^337)/337)

+ (-(theNumber^338)/338) + ((theNumber^339)/339)

+ (-(theNumber^340)/340) + ((theNumber^341)/341)

+ (-(theNumber^342)/342) + ((theNumber^343)/343)

+ (-(theNumber^344)/344) + ((theNumber^345)/345)

+ (-(theNumber^346)/346) + ((theNumber^347)/347)

+ (-(theNumber^348)/348) + ((theNumber^349)/349)

+ (-(theNumber^350)/350) + ((theNumber^351)/351)

+ (-(theNumber^352)/352) + ((theNumber^353)/353)

+ (-(theNumber^354)/354) + ((theNumber^355)/355)

+ (-(theNumber^356)/356) + ((theNumber^357)/357)

+ (-(theNumber^358)/358) + ((theNumber^359)/359)

+ (-(theNumber^360)/360) + ((theNumber^361)/361)

+ (-(theNumber^362)/362) + ((theNumber^363)/363)

+ (-(theNumber^364)/364) + ((theNumber^365)/365)

+ (-(theNumber^366)/366) + ((theNumber^367)/367)

+ (-(theNumber^368)/368) + ((theNumber^369)/369)

+ (-(theNumber^370)/370) + ((theNumber^371)/371)

+ (-(theNumber^372)/372) + ((theNumber^373)/373)

+ (-(theNumber^374)/374) + ((theNumber^375)/375)

+ (-(theNumber^376)/376) + ((theNumber^377)/377)

+ (-(theNumber^378)/378) + ((theNumber^379)/379)

+ (-(theNumber^380)/380) + ((theNumber^381)/381)

+ (-(theNumber^382)/382) + ((theNumber^383)/383)

+ (-(theNumber^384)/384) + ((theNumber^385)/385)

+ (-(theNumber^386)/386) + ((theNumber^387)/387)

+ (-(theNumber^388)/388) + ((theNumber^389)/389)

+ (-(theNumber^390)/390) + ((theNumber^391)/391)

+ (-(theNumber^392)/392) + ((theNumber^393)/393)

+ (-(theNumber^394)/394) + ((theNumber^395)/395)

+ (-(theNumber^396)/396) + ((theNumber^397)/397)

+ (-(theNumber^398)/398) + ((theNumber^399)/399)

+ (-(theNumber^400)/400) + ((theNumber^401)/401)

+ (-(theNumber^402)/402) + ((theNumber^403)/403)

+ (-(theNumber^404)/404) + ((theNumber^405)/405)

+ (-(theNumber^406)/406) + ((theNumber^407)/407)

+ (-(theNumber^408)/408) + ((theNumber^409)/409)

+ (-(theNumber^410)/410) + ((theNumber^411)/411)

+ (-(theNumber^412)/412) + ((theNumber^414)/414)

+ (-(theNumber^414)/414) + ((theNumber^415)/415)

+ (-(theNumber^416)/416) + ((theNumber^417)/417)

+ (-(theNumber^418)/418) + ((theNumber^419)/419)

+ (-(theNumber^420)/420) + ((theNumber^421)/421)

+ (-(theNumber^422)/422) + ((theNumber^423)/423)

+ (-(theNumber^424)/424) + ((theNumber^425)/425)

+ (-(theNumber^426)/426) + ((theNumber^427)/427)

+ (-(theNumber^428)/428) + ((theNumber^429)/429)

+ (-(theNumber^430)/430) + ((theNumber^431)/431)

+ (-(theNumber^432)/432) + ((theNumber^433)/433)

+ (-(theNumber^434)/434) + ((theNumber^435)/435)

+ (-(theNumber^436)/436) + ((theNumber^437)/437)

+ (-(theNumber^438)/438) + ((theNumber^439)/439)

+ (-(theNumber^440)/440) + ((theNumber^441)/441)

+ (-(theNumber^442)/442) + ((theNumber^443)/443)

+ (-(theNumber^444)/444) + ((theNumber^445)/445)

+ (-(theNumber^446)/446) + ((theNumber^447)/447)

+ (-(theNumber^448)/448) + ((theNumber^449)/449)

+ (-(theNumber^450)/450) + ((theNumber^451)/451)

+ (-(theNumber^452)/452) + ((theNumber^453)/453)

+ (-(theNumber^454)/454) + ((theNumber^455)/455)

+ (-(theNumber^456)/456) + ((theNumber^457)/457)

+ (-(theNumber^458)/458) + ((theNumber^459)/459)

+ (-(theNumber^460)/460) + ((theNumber^461)/461)

+ (-(theNumber^462)/462) + ((theNumber^463)/463)

+ (-(theNumber^464)/464) + ((theNumber^465)/465)

+ (-(theNumber^466)/466) + ((theNumber^467)/467)

+ (-(theNumber^468)/468) + ((theNumber^469)/469)

+ (-(theNumber^470)/470) + ((theNumber^471)/471)

+ (-(theNumber^472)/472) + ((theNumber^473)/473)

+ (-(theNumber^474)/474) + ((theNumber^475)/475)

+ (-(theNumber^476)/476) + ((theNumber^477)/477)

+ (-(theNumber^478)/478) + ((theNumber^479)/479)

+ (-(theNumber^480)/480) + ((theNumber^481)/481)

+ (-(theNumber^482)/482) + ((theNumber^483)/483)

+ (-(theNumber^484)/484) + ((theNumber^485)/485)

+ (-(theNumber^486)/486) + ((theNumber^487)/487)

+ (-(theNumber^488)/488) + ((theNumber^489)/489)

+ (-(theNumber^490)/490) + ((theNumber^491)/491)

+ (-(theNumber^492)/492) + ((theNumber^493)/493)

+ (-(theNumber^494)/494) + ((theNumber^495)/495)

+ (-(theNumber^496)/496) + ((theNumber^497)/497)

+ (-(theNumber^498)/498) + ((theNumber^499)/499).







return newValue.



<hr></blockquote>



[ 11-20-2002: Message edited by: Rick1138 ]</p>

Comments

  • Reply 1 of 3
    I like chocolate chip cookies myself.
  • Reply 2 of 3
    I can't believe that works at all. With all of that aritmetic the round off errors due to the use of fixed arithmetic must be horrendous.



    There are any number of books detailing algorithms like this. Did you try Knuth?
  • Reply 3 of 3
    Believe it or not that works very well.In the upper reaches of its bounds it is accurate to six decimal places.Have faith in the fpu,it is surprisingly fast and accurate.I tried Cormen,I have a book on approximation that I bought a while ago as a reference ,I'll have to dig it out.In general I hate approximation,but i dont have a choice here.
Sign In or Register to comment.