Oberon Community Platform Forum
October 14, 2019, 06:46:32 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Problem with LONGCOMPLEX  (Read 2830 times)
darek
Jr. Member
**
Posts: 59


« on: June 04, 2012, 12:18:51 PM »

Hi All,
In my calculations,   I am trying to use COMPLEX, and LONGCOMPLEX data types, instead of using PACO modules.
So, I tried to derive (from PACO) some simple functions for both types.
The code from the module below does not compile for the LONGCOMPLEX (it seems that there is a problem with IMAG ).

Is this a  compiler bug?

Regards,
  Darek


MODULE TestComplex;
IMPORT Log := KernelLog, Math, MathL;



PROCEDURE ExpL*( z: LONGCOMPLEX ): LONGCOMPLEX;
   VAR coef, re, real, im, imag: LONGREAL;  exp: LONGCOMPLEX;
   BEGIN
      (* Euler's formula *)
      re := RE( z );
        im := IM( z );
        coef := MathL.exp( re );
        real := coef * MathL.cos( im );
      imag := coef * MathL.sin( im );

      exp := real + imag * IMAG; (* <-- COMPILATION ERROR: incompatible operands, conversion failer ? *)
         RETURN exp
   END ExpL;



PROCEDURE Exp*( z: COMPLEX ): COMPLEX;
   VAR coef, re, real, im, imag: REAL;  exp: COMPLEX;
   BEGIN
      (* Euler's formula *)
      re := RE( z );
        im := IM( z );
        coef := Math.exp( re );
        real := coef * Math.cos( im );
      imag := coef * Math.sin( im );

      exp := real + imag *IMAG;
         RETURN exp
   END Exp;

(** Trigonometric Functions *)

 PROCEDURE Sin*( z: COMPLEX): COMPLEX;
   VAR sin: COMPLEX;
   BEGIN
      sin := (Exp( IMAG  * z ) - Exp( -IMAG * z )) / (2 * IMAG);
      RETURN sin
   END Sin;

PROCEDURE SinL*( z: LONGCOMPLEX): LONGCOMPLEX;
   VAR sin: LONGCOMPLEX;
   BEGIN
      sin := (ExpL( IMAG  * z ) - ExpL( -IMAG * z )) / (2 * IMAG);
      RETURN sin
   END SinL;


PROCEDURE Run*;
  VAR a, b, z  : COMPLEX;
 
  BEGIN
     a :=  1 + 3*IMAG;
     b :=  2 - 6*IMAG;
     z := a *b;
     z := Exp(z);
END Run;

BEGIN
END TestComplex.

TestComplex.Run ~

SystemTools.Free TestComplex ~
Logged
darek
Jr. Member
**
Posts: 59


« Reply #1 on: June 12, 2012, 07:53:00 PM »

Hi All,
  All problems have been solved by Felix.
 
 Regards,
   Darek
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!