• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

update: C programming help (log function)

Omegachi

Diamond Member
// hi guys, my math.h file don't work and i need to use a log() function. can someone show me the function to do log base 2?

new question, how do you break out of main()?

break; don't work.
 
Shift right by 23, then subtract 127..

This works for 32 bit IEEE float.


Try the following code:

input: float v
output: int c ------- log2(v)

c = ((*(int *) &v) >> 23) - 127;
 
you can probably approximate it with a taylor series expansion. google it

but just wondering how is math.h not working?
 
Originally posted by: Omegachi
yea.... trying to make a double log( int n) file. without math.h

how can math.h not work? are you compiling with gcc? might need a -lm flag at the end
 
Back
Top