My small modification to E?in's version is that my macro assumes that st(0) already contains the input float...


facos MACRO
        fmul st(0), st(0)     
        fld1
        fsubr
        fsqrt
        fxch
        fpatan
ENDM


arc cosine of 0.5f is 60 degrees.
We can use this knowledge to test the macro:


;Get arc cosine of 0.5f
fld fphalf
facos
;Now multiply by (180/pi) to convert radians to degrees
fld fp180
fldpi
fdiv
fmul
;Now store the angle value to a dword
fistp dwAngle


We can see that the answer is nothing like the 60 degrees it should be.
Does anyone see the error in the macro, or has a working acos?
(I've asked this before :( )
Posted on 2005-04-25 09:55:02 by Homer
Nevermind, I sorted it out.

The problem was that the float parameter needs to be loaded TWICE onto the fpu for facos.


facos MACRO
        fmul st(0), st(0)     
        fsubr fp1
        fsqrt
        fxch
        fpatan
ENDM

;Use it like this...
fld fphalf
fld fphalf
facos




The output is an angle in floating radians, which can be converted to degrees as shown in the previous post.

My bad :)

Posted on 2005-04-25 10:18:41 by Homer
Here's another version from a runtime lib :)


facos MACRO
fld1
fadd st(0), st(1)
fld1
fsub st(0), st(2)
fmulp st(1), st(0)
fsqrt
fxch st(1)
fpatan
ENDM

Posted on 2005-04-25 10:26:29 by f0dder