gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] complex types


From: Andreas Fischlin
Subject: Re: [Gm2] complex types
Date: Mon, 15 Dec 2008 16:28:33 +0100
User-agent: Thunderbird 2.0.0.18 (Macintosh/20081105)

Hi Gaius,

I am simply using CMath to implement whatever MathLib0 etc. I wish to implement. That should not break any legacy code. I have of course a legacy implementation of MathLib0 that uses portably algorithms if you wish to have a legacy implementation in order to have not the least significat bit being of max precision. However, I generally use CMath, since it is to the least significant bit precise, even if you use it as implementation of a REAL or even SHORTREAL definition of the procedure. RETURNing the long real value exploits the assignment compatibility, e.g.

    PROCEDURE Sin(x: REAL): REAL;
    BEGIN
      RETURN CMath.sin(x)
    END Sin;

 and that's about all there is.

Regards,
Andreas
 

Gaius Mulley wrote:
Andreas Fischlin <address@hidden> writes:

  
Arn't C library conversion routines already longreal? MathLib0 definition looks
similar to this (within RAMSES/RASS):

DEFINITION FOR C MODULE CMath; 

  PROCEDURE sqrt(x : LONGREAL) : LONGREAL;
  PROCEDURE sin (x : LONGREAL) : LONGREAL;
  PROCEDURE cos (x : LONGREAL) : LONGREAL;
  PROCEDURE exp (x : LONGREAL) : LONGREAL;
  PROCEDURE log (x : LONGREAL) : LONGREAL;
  PROCEDURE atan(x : LONGREAL) : LONGREAL;

END CMath.

Similarly I expect conversion routines to be also double precision reals, i.e.
LONGREAL.

Regards,
Andreas
    

Hi Andreas,

I've just checked in some changes to MathLib0 - it now has a complete
set of LONGREAL functions and rebuilt the html documentation.

http://www.nongnu.org/gm2/gm2.html#SEC85

The definition module is now:

DEFINITION MODULE MathLib0 ;

(*
    Description: provides access to math functions.
*)

CONST
   pi   = 3.1415926535897932384626433832795028841972;
   exp1 = 2.7182818284590452353602874713526624977572;


PROCEDURE __BUILTIN__ sqrt (x: REAL) : REAL ;
PROCEDURE __BUILTIN__ sqrtl (x: LONGREAL) : LONGREAL ;
PROCEDURE __BUILTIN__ sqrts (x: SHORTREAL) : SHORTREAL ;

PROCEDURE exp (x: REAL) : REAL ;
PROCEDURE expl (x: LONGREAL) : LONGREAL ;
PROCEDURE exps (x: SHORTREAL) : SHORTREAL ;

PROCEDURE ln (x: REAL) : REAL ;
PROCEDURE lnl (x: LONGREAL) : LONGREAL ;
PROCEDURE lns (x: SHORTREAL) : SHORTREAL ;

PROCEDURE __BUILTIN__ sin (x: REAL) : REAL ;
PROCEDURE __BUILTIN__ sinl (x: LONGREAL) : LONGREAL ;
PROCEDURE __BUILTIN__ sins (x: SHORTREAL) : SHORTREAL ;

PROCEDURE __BUILTIN__ cos (x: REAL) : REAL ;
PROCEDURE __BUILTIN__ cosl (x: LONGREAL) : LONGREAL ;
PROCEDURE __BUILTIN__ coss (x: SHORTREAL) : SHORTREAL ;

PROCEDURE tan (x: REAL) : REAL ;
PROCEDURE tanl (x: LONGREAL) : LONGREAL ;
PROCEDURE tans (x: SHORTREAL) : SHORTREAL ;

PROCEDURE arctan (x: REAL) : REAL ;
PROCEDURE arctanl (x: LONGREAL) : LONGREAL ;
PROCEDURE arctans (x: SHORTREAL) : SHORTREAL ;

PROCEDURE entier (x: REAL) : INTEGER ;
PROCEDURE entierl (x: LONGREAL) : INTEGER ;
PROCEDURE entiers (x: SHORTREAL) : INTEGER ;

END MathLib0.


I've followed PIM2, PIM3, PIM4 (for sqrt, exp, ln, sin, cos, tan,
arctan and entier).  However do you think it better to default to use
the LONGREAL versions and allow users to specify lower precision
variants if desired?

So in the case of tan we might have 

PROCEDURE tan (x: LONGREAL) : LONGREAL ;
PROCEDURE tanr (x: REAL) : REAL ;
PROCEDURE tans (x: SHORTREAL) : SHORTREAL ;

given that LONGREAL, REAL, SHORTREAL are assignment compatible.
However they are not _expression_ compatible so this change will
probably break legacy code..

regards,
Gaius
  

--
________________________________________________________________________
Dr. Andreas Fischlin, Ph.D., Group Director

Terrestrial Systems Ecology
Institute of Integrative Biology: Ecology, Evolution, Infectious Disease
Department of Environmental Sciences, ETH Zurich

Address:
ETH Zurich, CHN E21.1
8092 Zurich, Switzerland

Phone: +41 44 633-6090 / Fax: +41 44 633-1136
http://www.sysecol.ethz.ch/Staff/af/
http://www.sysecol.ethz.ch/

     _/_/_/ _/_/_/ _/  _/
    _/       _/   _/  _/   Eidgenoessische Technische Hochschule Zuerich
   _/_/_/   _/   _/_/_/   Swiss Federal Institute of Technology Zurich
  _/       _/   _/  _/   Ecole polytechnique federale de Zurich
 _/_/_/   _/   _/  _/   Politecnico federale de Zurigo

             Make it as simple as possible, but distrust it!
________________________________________________________________________
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]