Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!sundc!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: comp.lang.c Subject: Re: canonical values - an amenity Message-ID: <296@hadron.UUCP> Date: Sun, 14-Dec-86 23:34:52 EST Article-I.D.: hadron.296 Posted: Sun Dec 14 23:34:52 1986 Date-Received: Tue, 16-Dec-86 19:30:00 EST References: <1542@batcomputer.tn.cornell.edu> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 20 Summary: Double doesn't necessarily hold everything. In article <1542@batcomputer.tn.cornell.edu> garry%cadif-oak@cu-arpa.cs.cornell.edu.arpa writes: >the property that a pointer of any type cast to (void *) and back again >is guaranteed to emerge unharmed. >What I would like is to be able to do the same thing with *any* kind of >(primitive) value, not merely pointer values!!! (Why do things half-way >in the language ??) > (unknown)pointer -> (double)(long)pointer > (unknown)long -> (double)long Unfortunately, there's no guarantee that a double will not lose low-order bits in the mantissa when converting a long. This is especially a problem if the "long" happens to be a pointer. E.g., 32-bit long 0x7fffffff to 32-bit double with 8-bit exponent and 24-bit mantissa loses 8 bits of precision. (Just f'r'instance.) Unions are sometimes used for this purpose: they are guaranteed to be as large as the largest object contained therein. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP} jsdy@hadron.COM (not yet domainised)