www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/15/02:29:30

Message-Id: <199605150619.AA00859@sun17.thp.Uni-Koeln.DE>
From: brenig AT thp DOT Uni-Koeln DOT DE (Wolfram Brenig)
Date: Wed, 15 May 1996 08:19:03 +0200
To: djgpp AT delorie DOT com
Subject: V2.x and -On

So once again I have to bug you friendly DJGPP gurus with one
these problems I experience with V2.x : I am getting unexpected
SIGFPE's in combination with lengthy algebraic expressions if
compiled with -On.

First, I am *not* claiming the code snipped below is particularly 
sensible. *Neither* do I claim that usually one should write programs 
like that. It just happens that while using somewhat lengthy algebraic
expressions, the one below exaggerated for illustration purpose, I encounter 
floating point exceptions in combination with *optimized* code and V2.x. 
If compiling the code with V1.x *or* V2.x and

gcc fuu.cc -lm

everything looks ok. The output is: -5.701e+00 in both cases. However 
compiling with * V2.x * and

gcc -On fuu.cc -lm    (n=1,2,3)

I get

Exiting due to signal SIGFPE
Floating Point exception at eip=00001665
eax=3ff00000 ebx=00000000 ecx=0005304c edx=3fe00000 esi=3fe00000 edi=0000d8c0
ebp=0004d898 esp=0004d860 cs=00a7 ds=00af es=00af fs=008f gs=00bf ss=00af
Call frame traceback EIPs:
  0x00001665   _main+193
  0x00003d9f   ___crt1_startup+115

Now, just to confuse me, compiling with * V1.x * and equivalently

gcc -On fuu.cc -lm

everything seems fine. Again the output is: -5.701e+00 and *no* FPE.

Since the expression in the code snipped does not seem ill-defined,
does this imply some problems with optimizing and V2.x ?
Any help is most appreciated. I am *not* subscribing to the djgpp mailing
list so please mail your comments to: brenig AT thp DOT uni-koeln DOT de

Thanks :-) !

==========================================================

#include <stdio.h>
#include <math.h>
#define QDR(x) ((x)*(x))
#define CUB(x) ((x)*(x)*(x))

int main() {
	double	t=5.,d0=1.,a=2.,b=1.,c=-.6,be=.5,ga=2,nu=.66,T=.5;
	double	tm1=T-1,emt=1-T,th2=QDR(T);
	double	th4=QDR(th2),tm1h2=QDR(tm1),atm1h2=QDR(a*tm1);
	double	pa=pow(emt,ga),pe=pow(T,be),
					ex=exp(a/T);
	double	F;
	F=b*pa*((be*c*th2*tm1*(2*be*
		tm1+ga*T+emt)*pow(T,2*be)+ex*(b*c*
		(atm1h2-a*T*tm1*(be*tm1+3*ga*T-2*tm1)+
		ga*CUB(T)*(be*tm1+T*(2*ga-1)))*pa+be*
		T*tm1*(a*tm1-T*(be*tm1+ga*T+emt)))*
		pe-b*(2*atm1h2-2*a*T*tm1*(2*ga*T+emt)+
		ga*th4*(2*ga-1))*QDR(ex)*pa)/(th4*QDR(pe+b*ex*
		pa)*tm1h2)-(c*th2*(QDR(be*tm1)+
		be*tm1*(2*ga*T+emt)+ga*th2*(ga-1))*pe-
		(atm1h2-2*a*T*tm1*(ga*T+emt)+ga*th4*
		(ga-1))*ex)/(th4*(pe+b*ex*pa)*tm1h2)
		+(be*T*tm1*pe-b*(a*tm1-ga*th2)*ex*pa)*
		(c*T*(be*tm1+ga*T)*pe+(a*tm1-
		ga*th2)*ex)/(th4*QDR(pe+b*ex*pa)*tm1h2)
		-2*(c*pe-ex)*QDR(be*T*tm1*pe-b*
		(a*tm1-ga*th2)*ex*pa)/(th4*CUB(pe+b*ex*pa)*tm1h2)
	);
	printf("%12.3e\n",F);
	return 1;
}

- Raw text -


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