logarithm function

Post » Thu Nov 07, 2013 2:58 am

The other day I needed a way to compute a natural logarithm, but unfortunately neither Papyrus nor SKSE seem to offer this function. So I looked around for a way to evaluate or at least approximate the result, which led me to http://en.wikipedia.org/wiki/Logarithm#Power_series . The first method mentioned there (Taylor series) only works between 0 and 2, so I focused on the arctanh method. Of course, Papyrus doesn't provide arctanh either, so this is what I ended up implementing:

Float Function ApproximateNaturalLog(Float x, Float precision)	precision *= 2 ; since we double the result at the end	Float term = (x - 1) / (x + 1)	Float step = term * term	Float result = term	Float divisor = 1	Float delta = precision	While delta >= precision		term *= step		divisor += 2		delta = term / divisor		result += delta	EndWhile	Return 2.0 * resultEndFunction

The idea is that it will continue evaluating smaller and smaller elements of the series until the difference it makes to the overall result gets small enough to be ignored.

This seems to work okay so far, but I wonder if there's some better way to go about this. Has anyone else had to compute logarithms in Papyrus before? How did you do it?

User avatar
Jordan Fletcher
 
Posts: 3355
Joined: Tue Oct 16, 2007 5:27 am

Post » Wed Nov 06, 2013 11:36 pm

I think PLB added it to SKSE, so it'll be in the next release whenever that may be :smile:
User avatar
Laura Shipley
 
Posts: 3564
Joined: Thu Oct 26, 2006 4:47 am


Return to V - Skyrim