[gnu.gcc.bug] Small numbers

mpope@augean.oz.au (Michael T Pope) (10/26/89)

(Sun4/Sparc, SunOS 3.?)
I am having trouble with small floating point numbers, as shown by the
following program.
---------------foo.c------------------
#include <stdio.h>
#include <values.h>

static float smallest_positive_float = MINFLOAT;
static float smallest_negative_float = -MINFLOAT;
static double smallest_positive_double = MINDOUBLE;
static double smallest_negative_double = -MINDOUBLE;

int main() {
  fprintf(stderr, "%e %e\n", smallest_positive_float, MINFLOAT);
  fprintf(stderr, "%e %e\n", smallest_negative_float, -MINFLOAT);
  fprintf(stderr, "%e %e\n", smallest_positive_double, MINDOUBLE);
  fprintf(stderr, "%e %e\n", smallest_negative_double, -MINDOUBLE);
}
43 Crackle> cc -o foo foo.c
44 Crackle> foo
1.401298e-45 1.401298e-45
-1.401298e-45 -1.401298e-45
4.940656e-324 4.940656e-324
-4.940656e-324 -4.940656e-324
45 Crackle> gcc -v -o foo foo.c
gcc version 1.36
 /usr/local/gnu/gcc-cpp -v -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ foo.c /tmp/cca02420.cpp
GNU CPP version 1.36
 /usr/local/gnu/gcc-cc1 /tmp/cca02420.cpp -quiet -dumpbase foo.c -version -o /tmp/cca02420.s
GNU C version 1.36 (sparc) compiled by GNU C version 1.36.
default target switches: -mfpu -mepilogue -msun-asm
foo.c:6: warning: floating point number exceeds range of `double'
foo.c:7: warning: floating point number exceeds range of `double'
foo.c: In function main:
foo.c:12: warning: floating point number exceeds range of `double'
foo.c:13: warning: floating point number exceeds range of `double'
 /usr/local/gnu/gcc-as -o foo.o /tmp/cca02420.s
/tmp/cca02420.s:5:cannot create floating-point number
/tmp/cca02420.s:8:cannot create floating-point number
/tmp/cca02420.s:11:cannot create floating-point number
/tmp/cca02420.s:14:cannot create floating-point number
/tmp/cca02420.s:31:cannot create floating-point number
/tmp/cca02420.s:34:cannot create floating-point number
 /usr/local/gnu/gcc-ld -o foo /lib/crt0.o foo.o /usr/local/gnu/gcc-gnulib -lc
46 Crackle> foo
-NaN 1.401298e-45
-NaN -1.401298e-45
-NaN -NaN
-NaN -NaN


I checked the source of values.h--- as expected it was picking up
/usr/include/values.h, which contains---
#ifdef sun
...
#define MINDOUBLE       4.94065645841246544e-324
#define MINFLOAT        ((float)1.40129846432481707e-45)
...

The version of gas is "1.34 (I guess)" according to gas -v.

Cheers,
Mike Pope

metz@iam.unibe.ch (Igor Metz) (10/26/89)

In article <8910250958.13737@munnari.oz.au> mpope@augean.oz.au (Michael T Pope) writes:
>(Sun4/Sparc, SunOS 3.?)
>I am having trouble with small floating point numbers, as shown by the
>following program.
>---------------foo.c------------------
>#include <stdio.h>
>#include <values.h>
>
>static float smallest_positive_float = MINFLOAT;
>static float smallest_negative_float = -MINFLOAT;
>static double smallest_positive_double = MINDOUBLE;
>static double smallest_negative_double = -MINDOUBLE;
>
>int main() {
>  fprintf(stderr, "%e %e\n", smallest_positive_float, MINFLOAT);
>  fprintf(stderr, "%e %e\n", smallest_negative_float, -MINFLOAT);
>  fprintf(stderr, "%e %e\n", smallest_positive_double, MINDOUBLE);
>  fprintf(stderr, "%e %e\n", smallest_negative_double, -MINDOUBLE);
>}

On SparcStation 1/ SunOS 4.0.3/ gcc 1.36 (using as not gas!) I get the
following:

bolek:/tmp% gcc gaga.c
gaga.c:6: warning: floating point number exceeds range of `double'
gaga.c:7: warning: floating point number exceeds range of `double'
gaga.c: In function main:
gaga.c:12: warning: floating point number exceeds range of `double'
gaga.c:13: warning: floating point number exceeds range of `double'
bolek:/tmp% a.out
1.401298e-45 1.401298e-45
-1.401298e-45 -1.401298e-45
4.940656e-324 4.940656e-324
-4.940656e-324 -46e-324

Comparing /usr/include/values.h and /usr/local/lib/gcc-include/float.h:
/usr/include/values.h (from Sun) contains
 #define MINDOUBLE       4.94065645841246544e-324
 #define MINFLOAT        ((float)1.40129846432481707e-45)

while /usr/local/lib/gcc-include/float.h (Produced by hard-params version 4.1,
CWI, Amsterdam) contains
 #define FLT_MIN ((float)1.17549435e-38)
 #define DBL_MIN 2.2250738585072014e-308

Which is correct?
-- 

Igor Metz                    X400: metz@iam.unibe.ch
Institut fuer Informatik     ARPA: metz%iam.unibe.ch@relay.cs.net
und angewandte Mathematik    UUCP: ..!uunet!mcvax!iam.unibe.ch!metz