From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu Subject: Re: [9fans] fun and scary evil C code From: "Russ Cox" Date: Thu, 20 Dec 2007 11:29:55 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20071220162924.124251E8C1C@holo.morphisms.net> Topicbox-Message-UUID: 1e88f8ca-ead3-11e9-9d60-3106f5b1d025 > Does C99 or any other C mandate the actual memory layout > of floats and doubles or the exact conversion of constant > representations? > I'm fairly sure they somehow mandate IEEE 754 properties, > but do they actually say that floats and doubles have to be stored > exactly that way in 4 or 8 bytes? > > Even if we assume sizeof(double) == 8, > what if my implementation is perverse and interleaves the exponent > bits amongst the mantissa bits? > Where is this disallowed in the standard(s)? It doesn't matter what the standard says; it matters what implementations do. C implementations are going to provide what the underlying hardware does, and almost all hardware does IEEE 754. > as long as the conversion you're after has an exact ieee representation, > i can't see how two compliant implementations could come up with > differing representations. (two different numbers can't have the same > ieee representation, except -0 and +0.) the conversion process doesn't > need any floating point itself and the only interpolation comes when > numbers don't have exact representations. Historically, it has not always been true that decimal <-> binary conversion of doubles has been precise enough to replicate a specific bit pattern. While conversion doesn't require floating point, it is often done in floating point anyway for convenience. Russ