Mail Archives: djgpp/1992/08/27/10:10:49
doprnt can't print Infs and NaNs (not a number). If you try to print these
'numbers', go32 reports an Exception 14. This can be shown with the
following program:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
main()
{
printf(" 1.0/0.0 = % f\n-1.0/0.0 = % f\n", 1.0/0.0, -1.0/0.0);
printf("asin(2.0) = % f\n", asin(2.0));
exit(0);
}
compile with
%gcc -o print print.c -lm
The following patch solves the problem. I suggest to apply this patch
after the patch sent by David M. Ronis (ronis AT ronis DOT chem DOT mcgill DOT ca).
(I think the patches are orthogonal, but I'm not sure).
Dieter
*** doprnt.org Wed Aug 26 08:03:36 1992
--- doprnt.c Thu Aug 27 07:13:06 1992
***************
*** 51,56 ****
--- 51,58 ----
flags&SHORTINT ? (short basetype)va_arg(argp, int) : \
va_arg(argp, int)
+ static int nan = 0;
+
#if 0
#define todigit(c) ((c) - '0')
#define tochar(n) ((n) + '0')
***************
*** 264,271 ****
*buf = NULL;
size = cvt(_double, prec, flags, &softsign, *fmt, buf,
buf + sizeof(buf));
! if (softsign)
sign = '-';
t = *buf ? buf : buf + 1;
goto pforw;
case 'n':
--- 266,274 ----
*buf = NULL;
size = cvt(_double, prec, flags, &softsign, *fmt, buf,
buf + sizeof(buf));
! if (softsign && !nan) /* it's not a number, so it doesn't need a sign */
sign = '-';
+ nan = 0;
t = *buf ? buf : buf + 1;
goto pforw;
case 'n':
***************
*** 452,457 ****
--- 455,464 ----
if (expcnt = isspecial(number, startp, signp))
return(expcnt);
#endif
+ #ifdef __GO32__
+ if (expcnt = isspecial(number, startp))
+ return(expcnt);
+ #endif
dotrim = expcnt = gformat = 0;
fract = modf(number, &integer);
***************
*** 714,718 ****
--- 721,751 ----
else
(void)strcpy(bufp, "Inf");
return(3);
+ }
+ #endif
+
+ #ifdef __GO32__
+ isspecial(d, bufp)
+ double d;
+ char *bufp;
+ {
+ register struct IEEEdp {
+ unsigned manl:32;
+ unsigned manh:20;
+ unsigned exp:11;
+ unsigned sign:1;
+ } *ip = (struct IEEEdp *)&d;
+
+ if (ip->exp != 0x7ff)
+ return(0);
+ if (ip->manh || ip->manl)
+ {
+ strcpy(bufp, "NaN");
+ nan = 1; /* kludge: we don't need the sign, it's not nice
+ but it should work */
+ }
+ else
+ (void)strcpy(bufp, "Inf");
+ return(3);
}
#endif
- Raw text -