Oberon Community Platform Forum

Development => Merge Requests => Topic started by: sage on February 10, 2009, 12:34:20 PM



Title: Math, MathL
Post by: sage on February 10, 2009, 12:34:20 PM
Math and MathL lacks of many needed math functions  :(
For example, arccos, arctan2, power, tan...
Actually, arctan2 is very easy to realize.
The only change needed (example for MathL) is to replace existing inline -Arctan with this:
Code:
PROCEDURE -Arctan(x, y: LONGREAL): LONGREAL;
CODE {SYSTEM.i386, SYSTEM.FPU}
FLD QWORD [ESP]
FLD QWORD 8[ESP]
DB 0D9H, 0F3H (* FPATAN ST(1)/ST(0) *)
ADD ESP, 16
END Arctan;
, change existing arctan a little:
Code:
PROCEDURE arctan*(x: LONGREAL): LONGREAL;
BEGIN
RETURN Arctan2(1, x)
END arctan;
, and add arctan2 code:
Code:
PROCEDURE arctan2*(x, y: LONGREAL): LONGREAL;
BEGIN
RETURN Arctan2(x, y)
END arctan2;


Title: Re: Math, MathL
Post by: sage on February 10, 2009, 12:39:31 PM
arccos may be realized in that way:
Code:
PROCEDURE arccos*(x: LONGREAL): LONGREAL;
BEGIN
RETURN Arctan2(Sqrt(ABS(1 - x * x)), x)
END arccos;


Title: Re: Math, MathL
Post by: sage on February 10, 2009, 02:32:05 PM
Existing Math and MathL didn't comply even to "The Oakwood Guidelines for Oberon-2 Compiler Developers" http://www.europrog.ru/paper/bk1995-01e.pdf (http://www.europrog.ru/paper/bk1995-01e.pdf)
Definition of Math according to Guidelines:
Code:
DEFINITION Math;
   CONST
      pi = 3.14159265358979323846;
       e = 2.71828182845904523536;
     PROCEDURE   sqrt (x : REAL) : REAL;
   PROCEDURE  power (x,base : REAL) : REAL;
     PROCEDURE    exp (x : REAL): REAL;
   PROCEDURE     ln (x : REAL) : REAL; 
   PROCEDURE    log (x,base : REAL) : REAL;
   PROCEDURE  round (x : REAL) : REAL;
   PROCEDURE    sin (x : REAL) : REAL;
   PROCEDURE    cos (x : REAL) : REAL
   PROCEDURE    tan (x : REAL) : REAL;
   PROCEDURE arcsin (x : REAL) : REAL;
   PROCEDURE arccos (x : REAL) : REAL;
   PROCEDURE arctan (x : REAL) : REAL;
   PROCEDURE arctan2(x,y : REAL): REAL
     PROCEDURE sinh   (x:REAL):REAL;
   PROCEDURE cosh   (x:REAL):REAL;
   PROCEDURE tanh   (x:REAL):REAL;
   PROCEDURE arcsinh(x:REAL):REAL;
   PROCEDURE arccosh(x:REAL):REAL;
   PROCEDURE arctanh(x:REAL):REAL;
END Math.


Title: Re: Math, MathL
Post by: sage on February 11, 2009, 03:19:43 PM
Finally, I've found that BlackBox Component Builder has well done Math modules.
It seems BlackBox's license is GPL-like.
So, I hope we can use it in A2.
There are fully Oakwood Guidelines compliant replacements of A2's Math and MathL modules in attached archive.


Title: Re: Math, MathL
Post by: staubesv on February 16, 2009, 11:53:51 AM
Quote
It seems BlackBox's license is GPL-like
Hmm... I'll have a closer look at this license... actually, we don't want the GPL (or GPL-like) to be used in library modules since this implies GPL for modules that import the library.