PDA

View Full Version : log2() function


Omita
09-01-2005, 06:55 AM
I am posting this because I couldn't find anything in the past on the subject. But in short, Mel can only caculate log(), log10(), and log1p, not some of that other common Log Math operations and I didn't want to use the API. So... below is my little Log2(N) function, I hope it save someone some time.

This is what i needed to make my powers of 2 code.

- Hays //************************************************
// log2(N)
//************************************************
// The log base N of any number, v, can be calulated by log(v)/log(N) where
// the function log can have any base
//

proc float log2( float $variable )
{
return (log ($variable))/(log (2));
}

/*********** Mini-Docs *************

Example:log2(5);
// Result: 2.321928 //
*********************************/

Omita
12-15-2005, 03:57 PM
Thus, here is the function for logX(N)
//************************************************
// logX(N)
//************************************************
// The log base N of any number, v, can be calulated by log(v)/log(N) where
// the function log can have any base
//

proc float logX( float $base, float $variable )
{
return (log ($variable))/(log ($base));
};

/*********** Mini-Docs *************

Example:logX (2, 5); // log2(5)
//Result: 2.321928 //*********************************/

CGTalk Moderation
12-15-2005, 03:57 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.