🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6465

Floating point equality

#6465
From: Robert Firth
Date: Wed, 10 May 1989 17:28
38 lines
1891 bytes
In article <452@sdti.SDTI.COM> turner@sdti.UUCP (0006-Prescott K. Turner, Jr.) writes:

>I don't buy that.  Every language with a successful floating point type
>has comparison for equality.

Well, I recall one compiler that implemented fuzzy equality... but
seriously, when I wrote a Coral-66 compiler, I deliberately removed
floating-point equality.  If the user wrote

	IF x = y THEN ...

the compiler generated an error message. In the instruction manual,
I explained that floating test for equality was permitted only
against the singular points of the domain, and gave the following
very broad hint:

"The test should be rewritten as

	IF x-y = 0 THEN ...

 and read as 'if the subtraction of y from x yields underflow then...'"

The actual codegeneration for floating-point expressions was reviewed
very carefully, until I was convinced it was close to impossible to
generate anomalies. Thus, things like

	z := x+y;
	IF z - (x+y) = 0 THEN ...	-- always TRUE
	IF (x+y) - z = 0 THEN ...	-- always TRUE

	pi := 3.141592686;
	IF pi - 3.141592686 = 0 THEN ... -- always TRUE

could be relied upon.  The codegenerator performed no code rearrangement
that could not be guaranteed to yield the bitwise identical result (and
so for instance would not change "z-(x+y)" into "z-x-y").

As far as I know, nobody got bitten by a running program.
Technical Details
Message-ID: <3349@bd.sei.cmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!pt.cs.cmu.edu!sei!firth
References: <10253@orstcs.CS.ORST.EDU> <2400023@otter.hpl.hp.com> <451@sdti.SDTI.COM> <529@rodan.cs.utexas.edu> <452@sdti.SDTI.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!pt.cs.cmu.edu!sei!firth
From: firth@sei.cmu.edu (Robert Firth)
Newsgroups: comp.lang.misc
Subject: Floating point equality
Message-ID: <3349@bd.sei.cmu.edu>
Date: 10 May 89 17:28:26 GMT
References: <10253@orstcs.CS.ORST.EDU> <2400023@otter.hpl.hp.com> <451@sdti.SDTI.COM> <529@rodan.cs.utexas.edu> <452@sdti.SDTI.COM>
Reply-To: firth@sei.cmu.edu (Robert Firth)
Organization: Software Engineering Institute, Pittsburgh, PA
Lines: 38