hi, after the normals i wanted to try another thing, so here is a procedure to calculate ln x or log(e) x

hope it makes sense




asm_ln PROC X:float ; log(e) X

fldl2e ; log(2) e
fld1 ; calculate 1/log(2)e
fdivrp st(1), st
fld X
fyl2x ; calculate 1/log(2)e * log(2)X = log(e) x

ret

asm_ln ENDP

Posted on 2002-03-22 10:57:28 by 08/15
Is the acurracy of this code limited to [-1,1] range?
Posted on 2002-03-22 12:16:53 by bitRAKE
uh oh, i have to admit that i don't know for sure.
when i had a look at your macros i didn't quite understand what's going on...and why...

wuold you help me to understand it better?
Posted on 2002-03-22 13:01:19 by 08/15
I got the power function from Agner Fog:
http://www.asdf.org/~fatphil/x86/pentopt/26.html#26_10

...and then I read the Intel manuals. IIRC, the F2XM1 instruction has a limitation of [-1,1] range for accurate results. I was curious, but do not know (without the manual) if that limitation exists in the function you present above. I will read the manual and see what the possible limitations would be. I will document the algo better and repost - Agner didn't really document it either. :)
Posted on 2002-03-22 13:52:29 by bitRAKE
bitrake, intel documentaion says:
"the source operand in st(0) must be a non-zero positive number"

so i guess there has to be a check if it's zero at least...
but i don't know how to implement that efficiently.
Posted on 2002-03-22 15:18:37 by 08/15
In REAL4 format a negitive number would have the top bit set, and zero would be 0x00000000. Therefor, there is no difference is testing for a positive non-zero REAL4, and testing for a positive non-zero 32-bit integer.
asm_ln PROC X:float       ; log(e) X

cmp DWORD [X],0
jle Error

fld1 ; calculate 1/log(2)e
fldl2e ; log(2) e
fdiv
fld X
fyl2x ; calculate 1/log(2)e * log(2)X = log(e) x
ret

Error:
;?
ret
asm_ln ENDP


; ln ST(0) :: needs two more free stack spaces and ST(0) > 0
fln MACRO
fld1 ; log(2) e
fldl2e ; calculate 1/log(2)e
fdiv
fxch
fyl2x ; calculate 1/log(2)e * log(2)X = log(e) x
ENDM
Posted on 2002-03-22 20:01:05 by bitRAKE