I am trying to do a log2(x) but cannot seem to find any library function that does this. Any hints (yes I tried searching with no luck)?
Thanks,
memotick
I am trying to do a log2(x) but cannot seem to find any library function that does this. Any hints (yes I tried searching with no luck)?
Thanks,
memotick
Hint: AVR Libc Home Page
A little less digging perhaps?
http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html
First principles:
logxn = logy n / logy x
Where y could be, say 10 or e
GoForSmoke:
A little less digging perhaps?
Thing is, that's probably the single most valuable skill every programmer should have.
Thing is, that's probably the single most valuable skill every programmer should have.
And the second is, whilst digging, not being distracted by... oh look! It's a video of a kitten!
GoForSmoke:
A little less digging perhaps?
Thanks everyone, but this was especially helpful. I didn't realize math.h was even on my system until I tried it!
And of course you checked that site out to see what else you have and bookmarked it?
There's a link directly to the Libc library page on the Arduino Reference page. It's probably that way so you don't have to hunt for 2 links just to get to the useful info.
AWOL:
... not being distracted by... oh look! It's a video of a kitten!
Star Wars according to a 3 year old.
AWOL:
First principles:logxn = logy n / logy x
Exactly, so:
void setup ()
{
Serial.begin(115200);
Serial.println (log (65536) / log (2));
}
void loop () {}
Gives:
16.00
So there are 16 bits in 65536, so to speak.
Some interesting bithacks for log2 operations: - Bit Twiddling Hacks -
e.g. Find integer log base 2 of a 32-bit IEEE float : - Bit Twiddling Hacks -