delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/11/10/12:34:05

To: BILLM AT vaxc DOT cc DOT monash DOT edu DOT au, DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
From: A DOT APPLEYARD AT fs1 DOT mt DOT umist DOT ac DOT uk
Date: 10 Nov 93 16:45:30 GMT
Subject: Re: Not trapping overflow etc in Gnu C

  > Perhaps if you posted the source of your small test program then I [= Bill
Metzenthen <BILLM AT vaxc DOT cc DOT monash DOT edu DOT au>] suspect that an error would be
quickly found (probably by you [= A.Appleyard], just after posting ;-)

  And it was! I was masking off the wrong bits of the CW! Partly, I was a bit
foxed by the wording in my manual, which e.g. described the (mask bit to avoid
0.0/0.0 causing an interrupt, i.e. the NaN mask) as the "invalid operation
mask", which I thought meant "invalid opcode"!). I have now got it working.
  But a warning: I found that trying to printf() a NaN or an infinity still
causes interrupt 117 regardless of CW setting, as if printf() has its own way
to detect infinity and NaN.
  I apologise for wasting people's email time.

#include<stdio.h>
short i; double x=1,y=0,z;
/*-----*/
int bad(double x){long int*i=(void*)&x,j;
if((i[1]&0x7ff00000)!=0x7ff00000) return 0;
j=(i[1]&0x80000000)?-1:1; if((i[1]&0x000fffff)?:i[0]) j=j+j; return j&3;}
/*-----*/
void baddy(double x){char* s[4]={"OK","+inf","NaN","-inf"}; int*i=(void*)&x,j;
printf("%08x %08x ",i[1],i[0]); j=bad(x);
if(j) printf("%s\n",s[j]); else printf("%20.13e\n",x);}
/*-----*/
main(){
asm("fstcw _i"); i|=0x1f; asm("fldcw _i");
baddy(z=x/y); baddy(-x/y); baddy(x); baddy(y); baddy(y/y); baddy(-y/y);
x=1e300; baddy(x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x);}

C:\WORK>go32 a.out
c:/gcc/bin/go32.exe version 1.08 Copyright (C) 1991 DJ Delorie
7ff00000 00000000 +inf
fff00000 00000000 -inf
3ff00000 00000000  1.0000000000000e+00
00000000 00000000  0.0000000000000e+00
fff80000 00000000 NaN
fff80000 00000000 NaN
7ff00000 00000000 +inf

- Raw text -


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