Re: rules of fixed-point arithmetic



Andrew Reilly wrote:

Well, it's true that I'd forgotten about the bizzaro-land of PL/I and ADA "fixed point", where the scale factors not only aren't constant for the arithmetic, but which don't even have to be powers of two.

Well, they are either powers of 2 or 10, as PL/I allows for
binary or decimal base. (Independent of the underlying representation.
I have used versions that do decimal scaling on binary numbers.)

Scale factor and base are known at compile time.

I'm certain that every so often that becomes important, but glancing at the web, it's mostly so that people can write papers about neat ways to make it perform a little better.

In particular, it makes a HELL of a difference whether you are assuming
two things, either or both of which may be false:

1) All fixed-point numbers have the same precision.

2) Division of two fixed-point numbers is not something that you
have to worry about - either you don't need it, or its exact result
isn't critical.

I assumed those things because both are true in the vast bulk of the places where fixed point is actually *used*, as opposed to being worried about.

For PL/I the first is probably true for many variables
involved in a calculation, but constants have the precision
and scale factor as written, good or bad.
(snip)

Yes, division of fixed point numbers is a pain, since, as you point out, you have to deal with results that may not fit neatly into the range of your data. Whenever possible, the answer is to just not divide. When division is essential, you have to deal with it. One of the more convenient ways to do that is to define a division operator as x/(y*M), where M is a power-of-two scale factor that you select to ensure that your result is a fraction in the appropriate range: trading precision and range. I think that the only fixed point arithmetic where division isn't much of a pain is one where the number of bits devoted to integer values is the same as the number devoted to fractions, such as the 16.16 format that Knuth used in TeX.

PL/I provides the DIVIDE built-in function to specify the
desired quotient precision and scale. Some say that should
be the only way to divide.

-- glen

.



Relevant Pages

  • Re: new here, my lang project... PT2
    ... The scale is limited by the resolution of ... I see this as a precision vs. accuracy issue. ... > physics core ... > just I am not sure how necessary the partitioning is at present. ...
    (comp.object)
  • Re: float storage
    ... To increase the scale one must decrease the precision. ... SQL> create table numberz, ...
    (comp.databases.oracle.misc)
  • Re: float storage and usage
    ... offers the maximum scale and precision.. ... float offers with widest ranges. ... Putting a float into a primary key is definitely not recommendable. ...
    (comp.databases.ms-sqlserver)
  • Re: float storage
    ... information scale and precision I can't determine in advance (customer data ... can vary wildly) so I wanted to use the datatype that offers the maximum scale ... I used the oracle 9i docs to drive my decision. ...
    (comp.databases.oracle.misc)
  • Re: rules of fixed-point arithmetic
    ... All fixed-point numbers have the same precision. ... keep your scale factors to powers of two, which is IMO not unreasonable, ... multiplications by arbitrary rational numbers. ... don't have to re-scale at all, except for when you reduce an accumulator ...
    (comp.arch)