O Omegachi Diamond Member Mar 27, 2001 3,922 0 76 Feb 29, 2004 #1 // 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.
// 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.
E emmpee Golden Member Nov 26, 2001 1,100 0 0 Feb 29, 2004 #2 so you want to do it without using any math.h routines?
B br0wn Senior member Jun 22, 2000 572 0 0 Feb 29, 2004 #4 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;
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;
O Omegachi Diamond Member Mar 27, 2001 3,922 0 76 Feb 29, 2004 #5 yea.... trying to make a double log( int n) file. without math.h
D dighn Lifer Aug 12, 2001 22,820 4 81 Feb 29, 2004 #6 you can probably approximate it with a taylor series expansion. google it but just wondering how is math.h not working?
you can probably approximate it with a taylor series expansion. google it but just wondering how is math.h not working?
M MacBaine Banned Aug 23, 2001 9,999 0 0 Feb 29, 2004 #7 make sure you remember your -lm compile flag!
C cchen Diamond Member Oct 12, 1999 6,062 0 76 Feb 29, 2004 #8 Originally posted by: Omegachi yea.... trying to make a double log( int n) file. without math.h Click to expand... how can math.h not work? are you compiling with gcc? might need a -lm flag at the end
Originally posted by: Omegachi yea.... trying to make a double log( int n) file. without math.h Click to expand... how can math.h not work? are you compiling with gcc? might need a -lm flag at the end