From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,270d47706116d3c X-Google-Attributes: gid103376,public From: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: Can compilers do this? Date: 1996/02/25 Message-ID: #1/1 X-Deja-AN: 141024480 references: <4gjd6g$mfq@newsbf02.news.aol.com> <4gl344$q4j@wdl1.wdl.loral.com> organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-02-25T00:00:00+00:00 List-Id: Mark said "My guess is that on that machine signed zeros exist and that -0.0 < 0.0 and that -0.0 * 0.0 => 0.0, thus the above gives the right answer when given a -0.0." Mark, I think your guess is probably right (this was in response to the strange abs code for testing for zero). But note that if this was Ada code, then the compiler involved had a serious bug. In both Ada 83 and Ada 95, minus zero and plus zero must compare equal. The situation in Ada 83 is that minus zero does not exist in the language at all. A machine that generates minus zeroes is simply exhibiting a case where one Ada value can have multiple hardware representations. If this is the case, the compiler must ensure that these hardware representations are treated as identical in all contexts where the semantics of the value is well defined (an exception would be unchecked conversion, where in any case the result has some implementation dependence). The situation in Ada 95 is that minus zero is a recognized value, and certain operations in the language can tell the difference between minus zero and plus zero (and in fact MUST do so correctly if Signed_Zeroes is true). However, equality testing is not among these operations, and must work "correctly", i.e. plus and minus zero must compare equal. The other guess of course for the original code is that it came out of uninformed superstition (the same kind of superstition that says never compare floating-point values for equality), and that the compiler did things right, but the programmer did not know or believe that this was the case!