I just need the math function x^y with floating point.
But there is no straight function on the Pentium-FPU ?!?

How do I do it?

Posted on 2002-03-05 15:06:28 by VShader
Use Scali's power-routine:

``````
Power   PROC    a:REAL4, b:REAL4
LOCAL cw:WORD
LOCAL cwtemp:WORD

fstcw   [cw]            ; Save current control word
mov     ax, [cw]
or      ax, 0C00h       ; Set rounding control to chop
mov     [cwtemp], ax
fldcw   [cwtemp]

; c = exp(b*log(a));
fld     [b]
fld     [a]
fyl2x               ; st(0) = b*(2 log(a))
fld     st(0)       ; Duplicate log
frndint             ; Round to integer. st(1) = b*(2 log(a)), st(0) = (int)(b*(2 log(a)))
fld     st(1)       ; ...and duplicate log again
fsubr               ; st(0) = (b*(2 log(a)) - b*((int)(2 log(a))) (fraction only)
f2xm1               ; st(0) = 2^st(0) - 1 (2^x float portion)
fld1                ; add 1 again (why did that bastard sub it? :)
fscale              ; Calc the 2^x integer portion, and multiply with 2^x float portion, to get complete 2^x (based on 2^i * 2^f = 2^(i+f))
fstp    st(1)       ; Clean up stack (fscale doesn't pop the scale argument...)
fldcw   [cw]        ; Restore control word

ret
Power   ENDP
``````

/Delight
Posted on 2002-03-05 15:14:51 by Delight
Thanks :alright: