Topic: Fixed point


Author: bj@hatch.socal.com (Brendan Jones)
Date: Tue, 8 Mar 1994 19:24:03 GMT
Raw View
In article <2le95h$d9h@girtab.usc.edu> ekstrom@girtab.usc.edu (Harold Verner Ekstrom) writes:
>...[many examples of fixed point square root code deleted...]
>Most of this article gives code examples in assembly. I was wondering if
>there is any way to devise basic fixed point routines in C to make it more
>portable? I realize efficiency would suffer and many assembly commands
>are difficult to emulate in a high level language. So, what's the answer?

You have two options; You can use C++ classes.  Define fixed point
as a class, with operators such as *, / and square root.  The
catch is I tried this with Borland C++ and it was SLLLLLLOOOOOOWWW!
That may be a problem with their implementation; I see no reason
why it couldn't run faster.  Perhaps try other compilers...
(the efficiency isn't something like 10% you can ignore; I recall
it was at least 2 orders of magntitude).

Alternately, write a bunch of macros and resort to using binary
functions:
   x = fadd(y, fmult(z, a))
If you typedef your fixed variable type you have the option of
changing it to a float and providing an alternate set of macros
for the floating point operations.

:dream on.
I'd love to see C/C++ extended by the addition of a fixed point
datatype.

 eg. unsigned fixed x : 12:4;

where there are 4 bits in the binary fraction and 12 for the whole.
This'd be *much* faster to implement at the compiler level.  It'd
also simplify multiplying fixed variables with a different length
decimal fraction.   Do this yourself gets really convoluted...
:dream off.

cheers
bj
--
Internet: bj@hatch.socal.com or 71053.1201@compuserve.com (when hatch is down)
(Hatch has been having network problems of late; if your mail to hatch is
bounced or you expect and get no reply please try the Compuserve address)
 ---------------------------------------------------------------