Oxygen Basic

Information => Open Forum => Topic started by: Peter on September 20, 2011, 12:18:18 PM

Title: Atan2
Post by: Peter on September 20, 2011, 12:18:18 PM
Deleted
Title: Re: Atan2
Post by: Charles Pegge on September 20, 2011, 12:50:36 PM
Hi Peter,

it is just called atan(y,x)

atn(y/x) is the usual Basic function

Charles

PS pi() asin() and acos() deg() and rad() are also available
Title: Re: Atan2
Post by: Peter on September 20, 2011, 01:31:04 PM
Charles,

what about:   ArcTan
                   ArcSin
                   ArcCos ?
Title: Re: Atan2
Post by: Charles Pegge on September 20, 2011, 02:35:47 PM
Peter,

Allow me to introduce deff

This lets you create your own float macros. It allows you to extend the core maths functions.

For instance:

deff arctan fpatan

deff arctn fld1 : fpatan


You can see such macros encoded in the Oxygen source code src/o2keyw.bas


data       "asin 17 fld st0 : fmul st0 : fld1 : fsubp st1,st0 : fchs : fsqrt : fpatan"


Charles
Title: Re: Atan2
Post by: Charles Pegge on September 21, 2011, 04:03:21 AM

Hi Peter,

deff was introduced about 1 year ago in Alpha 10. I have kept quiet about it :)

Back soon. Then I will look at your code.

Charles
Title: Re: Atan2
Post by: Charles Pegge on September 21, 2011, 06:29:05 AM
Peter,

I try to hide them in the manual, but then I discover them a few months later. :)

Nice demo! the ball could almost pass for being intelligent.

There is a distance function available for 2D hypoteneuse.


dist = Sqr(dx*dx+dy*dy)

dist=hypot(dx,dy)

to make a customised 3D one using deff

deff hypot3
  fmul st0
  fxch st1
  fmul st0
  fxch st2
  fmul st0
  faddp st1
  faddp st1
  fsqrt
end deff

dist=hypot3(dx,dy,dz)



Charles
Title: Re: Atan2
Post by: Charles Pegge on September 21, 2011, 11:31:13 AM
Thanks Peter

deff will take any assembler instructions and dot labels but not macros or variable names. All parameters are automatically pushed onto the fpu stack.

for more general purpose macros, there is the traditional C #define and of course def which works a bit like a DOS batch file macro with its %1..%9 argument substitutions.

There is also a cleaner   alternative to using multi-line #define(...)

macro(a,b,c)
...
end macro


Charles