Xref: utzoo comp.lang.misc:3508 comp.arch:11497
Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!pardo
From: pardo@cs.washington.edu (David Keppel)
Newsgroups: comp.lang.misc,comp.arch
Subject: Re: Numbers (was Re: Fast conversions)
Keywords: fixed point integer
Message-ID: <9275@june.cs.washington.edu>
Date: 24 Sep 89 16:57:14 GMT
References: <832@dms.UUCP> <688@UALTAVM.BITNET> <9dAz02zs58y201@amdahl.uts.amdahl.com> <27935@winchester.mips.COM> <136@bbxsda.UUCP> <1989Sep22.201906.10618@utzoo.uucp> <6244@pt.cs.cmu.edu>
Reply-To: pardo@june.cs.washington.edu (David Keppel)
Organization: University of Washington, Computer Science, Seattle
Lines: 53

lindsay@MATHOM.GANDALF.CS.CMU.EDU (Donald Lindsay) writes:
>[Ada lets you say "type VOLT is delta 0.125"]
>[The problem is roundoff will be eighths of a volt.]
>[Conversions are bad: "volatage := 0.3" -- choose: 0.2 or 0.375]

I AMP SHOCKED by your REVOLTING example :-)

I believe that the Ada spec requires that the increments be at least
as fine as `delta', but that they can be finer if the compiler wants.
(If I'm wrong, assume that I have a language `adA' that does allow the
compiler to choose finer deltas.) Thus, if you have Ada on a machine
which does only decimal arithmetic operations (your average pocket
caluculator :-), then the implementation delta can be 0.1 units.
Given floats with sufficient range, it could even use floats.

This example points in a mostly uncharted direction for programming
languages: an assertion that something must be minimally true vs. an
assertion that something must be exactly true.

The `semantics' of Ada's delta are approximately

	type VOLT is delta 0.125;
	-- pragma require VOLT.delta <= 0.125

If you actually need a delta of 0.125, then you need to make a
stronger assertion.

	type VOLT is delta 0.125;
	-- pragma require VOLT.delta = 0.125

If I'm writing joe code that I want to run fast and some margin for
error is acceptable, then I'll probably write the above, even if all
that I want is resolution of 0.2 units.  Ideally, I should be able to
tell the compiler ``this is what I need, and here's a hint on how to
do it.''

	type VOLT is delta 0.2;
	-- pragma hint VOLT.delta = 0.125

Similarly, if you are troubled by conversions, you could hint that the
compiler should choose a finer delta

	type VOLT is delta 0.125;
	-- pragma hint VOLT.delta <= 1.0

No, no Ada compiler is required to let you do any of this.

Followups to comp.lang.misc.

	;-D on  ( Fixed pointless arithmetic )  Pardo
-- 
		    pardo@cs.washington.edu
    {rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo