Subject: Re: handling very small doubles
To: None <port-pc532@netbsd.org>
From: David Seifert <seifert@sequent.com>
List: port-pc532
Date: 09/15/1998 09:02:45
More data points:

DYNIX/ptx (x86):

eng4 cat > double.c
#include <stdio.h>
#define DBL_VAL         2.2250738585072014E-30
#define SDBL_VAL        "2.2250738585072014E-30"
void main () {
  double x;
  sscanf (SDBL_VAL, "%g", &x);
  printf ("%g %g %d %d %d\n",
          DBL_VAL, x, DBL_VAL > x, DBL_VAL == x, DBL_VAL < x);
}
eng4 cc double.c   
eng4 ./a.out
2.22507e-30 -1.98745 1 0 0
eng4

and on Digital Unix (alpha):

Floating exception(coredump)

BSDI (x86):

2.22507e-30 1.17747e-315 1 0 0

So it would appear that we're not alone.

> I just tried this on a NetBSD/i386 box (which has the same floating
> point format as the ns32k) and the result is:

I've found floating point coding bugs on ns32k machines with
code that supposedly worked fine on x86.   Not sure if it was
due to chip differences or the compiler.

And now for the answer:

You need to tell (s)scanf that you want to store the value
in a double rather than a float.

change 

	sscanf (SDBL_VAL, "%g", &x);

to

	sscanf (SDBL_VAL, "%lg", &x);

and it works fine on ptx, DU, and BSDI.  (No NetBSD machines here.  :-(  )

-Dave (lint is my friend)