delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/12/22/13:08:59

From: Andreas Henning <d2henan AT dtek DOT chalmers DOT se>
Subject: GO32 bug? (Or am I very wrong?)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Wed, 22 Dec 1993 18:58:40 +0100 (MET)

Hello!

I'm experiencing strange problems with the C++ part of the DJGPP
distribution. (Or at least I think that's what's causing the problems).

I have defined a class for complex numbers, but as soon as a call
a function with a complex type as an argument, I get a FP exception.
(eg, abs(z), where z is of the type complex, generates an exception.)

I'm using version 1.11 of the utilities, and gcc/gpp 2.5.4, both with
and without the maintenance patch. I have also tried to upgrade
to 2.5.7, but I get the same error.
The source compiles and links without errors or warnings.

I have also compiled Pov-Ray 2.0 using the above setups, and it works
flawlessly.

My source compiles and works as expected on the same machine (486dx/33 8 meg)
using Borland C++ 3.1, and on a Sparcstation ELC running SunOs 4.1.3 (gcc).

Any suggestions are very welcome, and I really hope this isn't a stupid 
error on my part.
(Sorry for making the letter so long, but I felt it necessary to include
 some source to explain.)

Regards,

Andreas Henning -- d2henan AT dtek DOT chalmers DOT se

The following source demonstrates an example:

-----------
#include <stdio.h>
#include <math.h>
#include "complex.h" 

double abs2(complex c);

main()
{
complex c;
double temp;

c = complex(2,3);   //2+3i
temp = sqrt(c.i*c.i+c.r*c.r); // This works ok
printf("%f\n",temp);
temp = abs2(c);               // FP Exception or 0, see below
printf("%f\n",temp);
temp = abs(c);                // same as abs2, but implemented in complex.cc
printf("%f\n",temp);
}

double abs2(complex c)
{
 return sqrt(c.i*c.i+c.r*c.r);      // Doesn't matter what I do here
 // return 5; // abs2 returns 0 if I replace the above line with this
}
-----------
/* complex.h -- definitions for a complex math library */
class complex {
   public:
         float r;          // real part
         float i;          // imaginary part

      complex();             // Constructor
      complex(float a, float b); // Another constructor
      ~complex();            // Destructor
      friend double abs(complex a);                  // Absolute value
	      };

---------------
 






- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019