delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/05/07/16:02:23

Date: Fri, 7 May 1993 15:47 EST
From: "Wonkoo Kim, EE, U. of Pittsburgh" <WKIM AT vms DOT cis DOT pitt DOT edu>
Subject: gcc hangs: Problem is narrowed down to DBL_MAX problem.
To: djgpp AT sun DOT soe DOT clarkson DOT EDU

Hi, again.

I tested with the short test*.c programs and I found that the defined constant 
DBL_MAX made the trouble.  Making the DBL_MAX constant smaller than the 
value defined in <float.h>, the gcc hanging problem goes away and no problem 
even for -O optimization.

This is very strange to me.  I showed the fine-tuned DBL_MAX value in the
following sample program.  This fine-tuned value may vary from system to
system, because various math-coprocessors exists and some people use
floating-point math emulation. 
If this is related to floating point problem, why did only my system hang?
(since 486-25MHz is a common cpu/math unit.)
Any comments?
If I replace the fine tuned value into <float.h>, is there any possible 
problems? (I don't care any small insignificant differences in output values.)

----- test3.c ----------------
#include <float.h>
#include <math.h>

#ifdef DBL_MAX
#undef DBL_MAX
#endif

/* #define DBL_MAX 1.7976931348623167e+308  quoted from <float.h>  */

/* #define DBL_MAX 1.79769313486231577e+308 */	/* made gcc hang if >=   */
#define DBL_MAX 1.79769313486231576e+308	/* gcc is okay with this */

double
test (double x, double y)
{
  if (y == 0.) return (23.6);
  if (x == 0.) return (DBL_MAX);
  return (10.*log10(y / x));
}
--------

A small question:  In this test3.c, y/x in log10() can possibly have big 
number greater than DBL_MAX.  What happen in such situation(big y and small x)?
y/x seems not just to be truncated to DBL_MAX in such cases before passing to 
log10().  I got "Inf" instead of DBL_MAX value when I printed the log10(y/x) 
value with "%g" format. (interesting. number becomes message string)
(BTW, changing to return(10.*(log10(y) - log10(x))); is a solution, but only 
for log() function.)

Thanks.

Wonkoo.

- Raw text -


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