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=0.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,270d47706116d3c,start X-Google-Attributes: gid103376,public From: bwburnsed@aol.com (BWBurnsed) Subject: Can compilers do this? Date: 1996/02/22 Message-ID: <4gjd6g$mfq@newsbf02.news.aol.com>#1/1 X-Deja-AN: 140717456 sender: root@newsbf02.news.aol.com organization: America Online, Inc. (1-800-827-6364) reply-to: bwburnsed@aol.com (BWBurnsed) newsgroups: comp.lang.ada Date: 1996-02-22T00:00:00+00:00 List-Id: I came across some very strange looking code that someone else wrote, long, long ago, and (apparently) in a universe far, far away. But before I make too many critical comments, I want to be sure I'm not missing something. Repeatedly in this code (in many files), there are places where a floating point variable is tested to see if it is negative. However, the way it is done is: if X * abs(X) < 0.0 then ... Is there (or was there ever) some pathological anomaly about floating point implementations that would make a conversion (abs) and floating point multiply preferable to testing a sign bit? Can, and will, optimizing compilers recognize the real test desired in such constructs, i.e. reduce it to a sign bit test? Also, suppose Y and X are floating point variables, and M and B are CONSTANT floating point variables (not named numbers) initialized to 1.0 and 0.0 respectively. If one writes Y := M * X + B ; can (and will) any compiler reduce this to Y := X ; If not, could it do so if M and B were named numbers? Thanks, BwB