The Mugen Fighters Guild

Help => M.U.G.E.N Development Help => MUGEN Class => Topic started by: JustNoPoint on October 14, 2015, 07:55:37 pm

Title: Ln (math) (Triggers)
Post by: JustNoPoint on October 14, 2015, 07:55:37 pm
Returns the natural logarithm of its argument. This produces slightly more accurate results than the otherwise equivalent expression log(e,(argument)).

Format:
ln(exprn)
Arguments:
exprn
Expression to compute the natural logarithm of (float).
Return type:
float
Error conditions:
Returns bottom if exprn evaluates to bottom, or if exprn is not positive.
Example:

Code:
value = ln(time)
  Sets value to the natural logarithm of the player's statetime.
Title: Re: Ln (math) (Triggers)
Post by: Ricepigeon on October 14, 2015, 08:18:37 pm
Tagging @Daniel9999999: since he has a lot more experience utilizing this trigger than I do and could probably clearly explain some practical uses for it better than I can, most notably using it to set boolean flags and such.
Title: Re: Ln (math) (Triggers)
Post by: jaede_ on October 14, 2015, 09:26:40 pm
Hello, it's interesting to note that Exponentiation (exp(x)) and the natural logarithm are inverse functions of each other in the interval (0,+inf), One use that Ricepigeon is referring to is the expression exp(2*ln(x))) which closely equals to 2^x  (not exactly equal, remember, MUGEN's floating point accuracy is baaaaaad). that we abused so we could just copypaste code and change one number and work faster, and also since we use it together with boolean flags, which work with powers of two, however, if you want to ACTUALLY use the integer number, you have to round it off some way, either floor(exp(2*ln(x)) + 0.5) or ceil(exp(2*ln(x)) - 0.5) will do the job for returning 2^x just fine and then you can just copypaste abuse :p. Note that x can be even an float, so you can use it to calculate square roots, inverses and stuff, more info about it here: http://mugenguild.com/forum/msg.64497

I am not sure of how fixed the "**" thing is in 1.0, but it's a nice tool to have if you don't trust MUGEN's basic operations... For WinMUGEN (compatible or exclusive) users, this (or Bia's method) is the way to go.