News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Inverse Trigonometric Functions?

Started by OceanJeff32, October 19, 2005, 02:35:54 AM

Previous topic - Next topic

OceanJeff32

I know the Intel Processor supports a super slow Inverse Tangent Function, but are there any good Inverse Cos and Sin() functions for Win API?  I suppose if my programs are going to implement a Sin and Cos lookup table, I might just be able to pull off a reasonable reverse look up from the same table.

And then use everyone's friend linear interpolation, to figure out what's not in the table itself.

Any better ideas?

later,

jeff c
:U
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

Ratch

OceanJeff32,
     You might find this link interesting. I would look into using the incremental Taylor series and a look up table.   Ratch

http://board.win32asmcommunity.net/index.php?topic=21430.15

Eóin

Here's a link to bMath which claim to have fast Trig functions. I never tried them though.

Attached are some of my macros for working out other trig functions based on the current FPU instructions.

[attachment deleted by admin]

OceanJeff32

Awesome!  I was thinking that I could do something similar with the Inverse Tangent Function, just convert everything to the tangent.  Nice!

I will be sure to give credit in my source / program too for using these routines, for now, I'm just experimenting.

later,

jeff c
:U
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

OceanJeff32

Hello Eoin,

Ok, I have a question about the arcsin macro

fAsin Macro ;ArcSin(st), 201-207 clocks

fld st
fmul st,st
fsubr PlusOne
fsqrt
fpatan
EndM

At the end the fpatan, what should be in st(1)??

I notice that a lot of the macros assume that something may be loaded into st(0) before the macro call, is this true?

help, and thanks again,

jeff c
:U
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

Eóin

Almost all functions are one parameter functions which operate on the value in st0. So in a one parameter function whatever was in st1 before the call should remain in st1. For two parameter functions, e.g. fPow the two parameters are passed in st0 & st1, after the call the answer should be in st0 and st1 will contain whatever was in st2.

Anywhere this doesn't happen is a bug ::).

So just a quick eg
fldpi
fld Value
fsin

fAsin

fstp Value
fstp Pi

After this code the var Value should be unchanged, and Pi should contain 3.14.... The stack should also be as it was prior to any of this code being called, except of course for any values in the higher position (st7, st6) because there wouldn't have been room for them.

raymond

QuoteAfter this code the var Value should be unchanged,

The var Value will have changed and now contain the asin(Value) if Value was between -1.0 and +1.0; otherwise, it would contain the NAN (Not A Number) code.

QuoteThe stack should also be as it was prior to any of this code being called, except of course for any values in the higher position (st7, st6) because there wouldn't have been room for them.

If st7 was not free before the code was processed, its content would be trashed and the Pi variable would now contain the NAN code. If both st5 and/or st6 were not free before the code was processed, their content would be trashed and the var Value would contain the NAN code. In addition, if any of the st5, st6 and st7 were not free, the Invalid operation flag of the Status Word would be set.

Quote;ArcSin(st), 201-207 clocks

I have seen 218-303 quoted for the FPATAN instruction and 83-87 quoted for the FSQRT instruction. That would add up to 300-390 in addition to the other instructions. Furthermore, the given range of 201-207 simply seems inadequate compared to that of the FPATAN.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

OceanJeff32

fAsin Macro ;ArcSin(st), 201-207 clocks
fld st
fmul st,st
fsubr PlusOne
fsqrt
fpatan
EndM

So, just a quickie on the above, since it's what I'm working on right now.

If I want to compute the arcsin of r/p

I first load r/p into st0, then use the above macro.
fld st                 // this will load st0 into st1, and into st0
fmul st, st          // this st0 = st0 * st0, st1 = st0 original
fsubr PlusOne     // st0 = 1 - st0 * st0, st1 = st0 original
fsqrt                  // st0 = sqrt(1 - st0*st0), st1 = st0 original
fpatan               // st0 = arctan of (st1/st0), so really this last statement goes like this:

st0 = arctan of (st0 original / sqrt(1 - st0 original *st0 original)

then the value in st0 is my answer. correct?

Well, I will find out shortly.

Thanks much for your help,

Jeff C
:U

I'm confused, does the attached program do what I think it does?

Have a look and let me know if any of you can figure it out.

Rho is the distance from the origin to the 3D point.
Theta is the angle that the projection of the line from the origin to the 3D point makes on the x-y plane, which is just the standard 2D Polar Theta.
Phi (fee) is the angle that the directed line segment from the origin to the 3D Point makes with the positive Z Axis. (Using Right Handed System).

I'm pressing forward, but I'm not sure about this program's conversion.

[attachment deleted by admin]
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

Eóin

Seem to work perfectly, how are you compiling it though? The exe you posted won't run so I had to compile the source myself.

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"