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: Tue, 16 Dec 2008 01:38:02 +0100
User-agent: Thunderbird 2.0.0.18 (Macintosh/20081105)

Hi Gaius,


Gaius Mulley wrote:
From: Gaius Mulley <address@hidden>
Subject: Re: [Gm2] complex types
To: Andreas Fischlin <address@hidden>
Cc: GM2 <address@hidden>

Andreas Fischlin <address@hidden> writes:

  
Arn't C library conversion routines already longreal? MathLib0
    

Hi Andreas,

ahh I believe there could be a problem here..
  
Indeed, I wasn't aware of the fact that LONGREAL is 128 bit in gm2 as you explain below.
  
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.
    

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

I think there might be a portability problem with the above (in gm2) -
as the C function sin is defined to take and return a 'double' whereas
in gm2 LONGREAL maps onto a 'long double'.

cut from 'man 3 sin':

  #include <math.h>

  double sin(double x);
  float sinf(float x);
  long double sinl(long double x);

I guess it works on systems where sizeof(double)==sizeof(long double)
or with Modula-2 compilers where TSIZE(LONGREAL)==sizeof(double).  But
it will fail with gm2 as

LONGREAL == long double
REAL == double
SHORTREAL == float


For example:

address@hidden:~/GM2$  gm2 -g -fcpp -c sizes.mod
address@hidden:~/GM2$  gm2 -g -fcpp sizes.mod
address@hidden:~/GM2$ ./a.out

size of CHAR is 1 bytes
size of INTEGER is 4 bytes
size of CARDINAL is 4 bytes
size of LONGINT is 8 bytes
size of LONGCARD is 8 bytes
size of SHORTREAL is 4 bytes
size of REAL is 8 bytes
size of LONGREAL is 16 bytes
size of BITSET is 4 bytes

address@hidden:~/GM2$ gcc sizes.c
address@hidden:~/GM2$ ./a.out

size of char is: 1 bytes
size of int is: 4 bytes
size of unsigned int is: 4 bytes
size of long int is: 8 bytes
size of long unsigned int is: 8 bytes
size of long long int is: 8 bytes
size of long long unsigned int is: 8 bytes
size of float is: 4 bytes
size of double is: 8 bytes
size of long double is: 16 bytes

So specifically at position "^^^" we see that gm2 will attempt to pass
a "long double" parameter to a C function expecting a "double"

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]