Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 11 May 2012 - 02:30 PM
Posted 11 May 2012 - 03:51 PM
Edited by taby, 11 May 2012 - 04:06 PM.
Posted 11 May 2012 - 04:06 PM
Edited by Ectara, 11 May 2012 - 04:07 PM.
Posted 11 May 2012 - 04:13 PM
No, these are not what I'm looking for; while alvaro is mathematically correct, I have no logarithm function to work with. Basically, I can easily return the integer part of y, where y = log2(x). However, I am having trouble finding the fractional part. For instance:
log2(12394) = 13.5973543.
I can easily get the answer 13, however I have remaining significant bits that I would like to use to determine the remaining 0.5973543.Has anyone done this sort of thing before?
Edited by taby, 11 May 2012 - 04:20 PM.
Posted 11 May 2012 - 04:24 PM
No, that's not what I'm looking for. I get an incomplete answer with my current implementation of log2(). I need to get more information, not less.
Edited by taby, 11 May 2012 - 04:43 PM.
Posted 11 May 2012 - 04:38 PM
No, these are not what I'm looking for; while alvaro is mathematically correct, I have no logarithm function to work with. Basically, I can easily return the integer part of y, where y = log2(x). However, I am having trouble finding the fractional part. For instance:
log2(12394) = 13.5973543.
I can easily get the answer 13, however I have remaining significant bits that I would like to use to determine the remaining 0.5973543.Has anyone done this sort of thing before?
Edited by alvaro, 11 May 2012 - 04:42 PM.
Posted 11 May 2012 - 05:07 PM
si32 E_mathLog2if(sf32 x){ register ui32 c; c = _E_floatGetExponentf(x); if(!c){ c = _E_floatGetMantissaf(x); c |= (c >> 1); c |= (c >> 2); c |= (c >> 4); c |= (c >> 8); c |= (c >> 16); c >>= 1; c -= ((c >> 1) & 0x55555555); c = (((c >> 2) & 0x33333333) + (c & 0x33333333)); c = (((c >> 4) + c) & 0x0f0f0f0f); c += (c >> 8); c = (c + (c >> 16)) & 0x3f; if(!c) return 0; c = (ui32)(-(23 - c)); } return _E_floatGetSignf(x) ? ~0 : (si32)c - 127; }
Edited by Ectara, 11 May 2012 - 05:09 PM.
Posted 11 May 2012 - 05:26 PM
inline float fast_log2(float val) { int *const exp_ptr = reinterpret_cast<int *>(&val); // For interpreting the float as a sequence of bits. int x = *exp_ptr; // This is obviously not the same thing as truncating the float by casting it as an int. const int log_2 = ((x >> 23) & 255) - 128; x &= ~(255 << 23); x += 127 << 23; *exp_ptr = x; // This is obviously not the same thing as casting the int as a float. val = ((-1.0f/3.0f) * val + 2) * val - 2.0f/3.0f; return val + log_2; }
Edited by taby, 11 May 2012 - 05:40 PM.
Posted 11 May 2012 - 06:00 PM
Posted 11 May 2012 - 06:17 PM
A quick search turned up http://www.netlib.org/cephes/ which seems to have C source code for all sorts of operations, including base 2 log.
Posted 11 May 2012 - 06:26 PM
For future reference, details like this are kind of a big deal.It's a "language with C syntax", I guess. No assembly, any processor with IEEE 754 support and at least 32bit two's complement integers. I can't use the standard library, but I have a great deal of replacements for most of the modules. Except the math.
Posted 11 May 2012 - 07:00 PM
Posted 11 May 2012 - 07:38 PM
Edited by iMalc, 11 May 2012 - 07:40 PM.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.