The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: OceanJeff32 on October 19, 2005, 02:35:54 AM

Title: Inverse Trigonometric Functions?
Post by: OceanJeff32 on October 19, 2005, 02:35:54 AM
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
Title: Re: Inverse Trigonometric Functions?
Post by: Ratch on October 19, 2005, 04:11:28 AM
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
Title: Re: Inverse Trigonometric Functions?
Post by: Eóin on October 19, 2005, 12:57:24 PM
Here's a link to bMath (http://www.bmath.net/bmath/index.html) 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]
Title: Re: Inverse Trigonometric Functions?
Post by: OceanJeff32 on October 19, 2005, 10:27:36 PM
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
Title: Re: Inverse Trigonometric Functions?
Post by: OceanJeff32 on October 20, 2005, 02:42:29 AM
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
Title: Re: Inverse Trigonometric Functions?
Post by: Eóin on October 20, 2005, 01:35:15 PM
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.
Title: Re: Inverse Trigonometric Functions?
Post by: raymond on October 21, 2005, 02:23:14 AM
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
Title: Re: Inverse Trigonometric Functions?
Post by: OceanJeff32 on October 21, 2005, 06:08:55 AM
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]
Title: Re: Inverse Trigonometric Functions?
Post by: Eóin on October 21, 2005, 06:13:26 PM
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.
Title: Re: Inverse Trigonometric Functions?
Post by: Farabi on October 23, 2005, 04:01:19 AM
THe attachment is not working here.