fixed point (was Shouldn't ANSI have provided ...)

Chris Torek chris at mimsy.umd.edu
Fri Feb 16 23:20:14 AEST 1990


(My apologies for the extensive quoting: I trimmed as much as I thought
reasonable.)

In article <17910 at rpp386.cactus.org> woody at rpp386.cactus.org
(Woodrow Baker) suggests that ANSI C should have included:
>>>>FIXED  i.e. fixed point math. ... would deal with chars, ints, longs
>>>>and quads.  There would be an assumed binary point in the middle of the
>>>>data...

(`short' seems to be missing from the above list.)

In article <1990Feb12.182343.14269 at utzoo.uucp> henry at utzoo.uucp
(Henry Spencer) points out:
>>>But *I* want the assumed binary point three bits from the right! :-)  This
>>>whole area is a massive swamp of conversion rules, overflow handling, etc.

In article <1990Feb13.114041.4178 at bath.ac.uk> exspes at bath.ac.uk (P E Smee)
writes:
>>PL/1 offered that.  In years of PL/1 programming, I believe I only ever
>>saw two or three programs (by anyone) that used it.  ... [Things were]
>>so baroque that it was actually usually easier to simply declare
>>everything as 'fixed bin (n,0)' (effectively, int/long/short) and [do
>>the work yourself].

This, of course, was Henry's point: fixed-point support is not nearly
as simple as it first appears.

In article <17950 at rpp386.cactus.org> woody at rpp386.cactus.org (Woodrow Baker)
writes:
>People, missed my point, that fixed point does not require conversions.
>A fixed int and an int are the same thing.  i.e., they should substitue
>for each other.  It is merely where you have the binary point.  Conversion
>to and from float, fixed, and int are not a problem.  fixed to float is
>real easy, float to fixed is also easy. ...

You cannot have it both ways:  Either a fixed int and an int are the
same thing---in which case, you do not need `fixed int' in the
language, because it is just another word for `int'---or they are
different.  If they are different, it is an untested change to C and
does not belong in the standard.

If the fixed point you propose is simply an alias, all you need to do is

	typedef long fixedpoint;

If the fixed point you propose comes with conversions, Henry's objection
applies.

`If you want PL/I, you know where to find it,'
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list