update: C programming help (log function)

Omegachi

Diamond Member
Mar 27, 2001
3,922
0
76
// 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.
 

br0wn

Senior member
Jun 22, 2000
572
0
0
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;
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
you can probably approximate it with a taylor series expansion. google it

but just wondering how is math.h not working?
 

cchen

Diamond Member
Oct 12, 1999
6,062
0
76
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