From 1098483408559780978
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7b33df5790e7ad92
X-Google-Attributes: gidf78e5,public
From: jcoffin@taeus.com (Jerry Coffin)
Subject: Re: complex design flaw (#1)
Date: 1999/03/15
Message-ID: <MPG.115705178a5dc0198994f@news.rmi.net>#1/1
X-Deja-AN: 455391634
X-NNTP-Posting-Host: 166-93-76-49.rmi.net
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <x88pv6fok3r.fsf@nbeckerpc.hns.com> <xaj3e3be4pu.fsf@korrigan.inria.fr> <01be6e30$aeae59e0$7d9cd4c7@danielp.interlog.com>
X-UID: 0000000001
X-Status: $$$T
X-Complaints-To: abuse@rmi.net
X-Trace: news1.rmi.net 921532327 18820 166.93.76.49 (15 Mar 1999 21:12:07 GMT)
Organization: TAEUS
NNTP-Posting-Date: 15 Mar 1999 21:12:07 GMT
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <01be6e30$aeae59e0$7d9cd4c7@danielp.interlog.com>, 
danielp@no_spam.com says...

[ ... ] 

> Incidently, I'm a little rusty on the bit layout of a floating point
> number; can I rely on
> 
> double x = 0.0;
> double y;
> 
> memset( &y, 0, sizeof(double) );
> 
> x == y ?
> memcmp( &x, &y, sizeof(double) ) == 0 ?

No, to both questions.  If you were restricting things to IEEE 
floating point, I _believe_ (though I'd have to do some looking to be 
sure) that setting all bits to zero will result in a value of zero.  
The reverse is NOT necessarily true -- in particular, any number in 
which the mantissa is zero has a value of zero, even if the exponent 
has non-zero bits.  Likewise, floating point will fairly frequently 
use 1's complement for the mantissa, and a bias representation for the 
exponent.  This means that all bits set to one in the mantissa is 
really a zero.  All bits set to zero in the exponent is an exponent of 
-128, and a zero exponent is what would normally be viewed as the 
value 128.

However, all of this is merely common practice: the C++ standard 
doesn't mandate that you use IEEE floating point (or anything 
particularly close to it), and there are still quite a few machines in 
the world that don't but may have C++ implementations anyway.  I 
haven't tried to figure out for sure, but I believe you could do a 
perfectly legal implementation of C++ using something like BCD, and 
(for example) use the value zero in a nibble to represent "Negative", 
"NaN" or something similar.

In the end, setting all bits of a floating point number to zero has 
only one effect according to the standard: undefined results.  You 
typically won't see floating-point traps simply by declaring something 
as floating point and setting it to an invalid bit-pattern, but 
there's nothing to stop the machine from doing this if it wants to.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




