From owner-freebsd-hackers Mon Feb 23 10:51:18 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA15896 for freebsd-hackers-outgoing; Mon, 23 Feb 1998 10:51:18 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from isbalham.ist.co.uk (isbalham.ist.co.uk [192.31.26.1]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA15872 for ; Mon, 23 Feb 1998 10:50:39 -0800 (PST) (envelope-from rb@gid.co.uk) Received: from gid.co.uk (uucp@localhost) by isbalham.ist.co.uk (8.8.7/8.8.4) with UUCP id SAA08579; Mon, 23 Feb 1998 18:49:26 GMT Received: from [194.32.164.2] by seagoon.gid.co.uk; Mon, 23 Feb 1998 18:49:25 GMT X-Sender: rb@194.32.164.1 Message-Id: In-Reply-To: <199802231619.KAA01344@chrome.jdl.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Mon, 23 Feb 1998 18:51:29 +0000 To: Jon Loeliger From: Bob Bishop Subject: Re: My Compiler Confusion Cc: hackers@FreeBSD.ORG Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >What are they(*) _really_ trying to do with that cast-cast-compare code? >((*) I am not the original author of this Work of Art...) I reckon they're trying to avoid using an FP constant if the integer is truly equivalent; might be cheaper on some targets. >Given that the constant really _doesn't_ fit in the integer, I think >the intent of this code is to essentially determine that fact and >then cause the compiler to do something else (more correct), than >silently substitute 0 in the generated code, as it does on the Solaris >box using the bbc or gcc. Well, according to the only reference I have to hand, "When a value of floating type is converted to integral type, the fractional part is discarded; if the resulting value cannot be represented in the integral type, the behaviour is undefined." (K&R II A6.3). So the Solaris behaviour is just fine. >How _should_ this cast-cast-compare test really be written to be >more correct? As a range test? Invert the test by taking max-int >and placing it in a float for the compare, which must be done >using a floating compare? If I'm right about what they're trying to do, the code is probably OK. -- Bob Bishop (0118) 977 4017 international code +44 118 rb@gid.co.uk fax (0118) 989 4254 between 0800 and 1800 UK To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message