Mail Archives: djgpp/1998/01/16/04:15:36
Can I cut in? I'm going to anyway...quick q about fixed type...
Shawn : If I have a fixed type variable called fix_var or whatever,
can I use -fix_var to get the negative value of it?
On Thu, 15 Jan 1998 08:32:27 +0000, Shawn Hargreaves
<Shawn AT talula DOT demon DOT co DOT uk> wrote:
>Shaun Jackman writes:
>>I searched the Allegro source but I couldn't find the definitions of the
>>fixed point typedef and its support functions.
>
>Look in allegro.h and search for "math routines".
>
>>What this comes down to specifically, is I need support for a 28.4 fixed
>>point structure, and I'm trying to figure out what the best way to do
>>this is.
>
>In terms of declaring, adding, comparing, etc, you can use normal
>integer types. The formula for a 28.4 multiply is (a*b)>>4, which you
>can code directly in C or with a macro if you don't mind the chance of
>overflow (Allegro uses inline asm to produce a 64 bit temp value, so it
>cannot overflow before I shift it back down to the correct range, but
>this is a much bigger issue with 16 fractional bits than if you are only
>using four). Division is the other way round, (a<<4)/b, so the same temp
>overflow problem can occur.
>
>>Also, I would like to know the overhead of the ftofix and fixtof
>>functions.
>
>The fixtof() is just a divide by 65536.0. Converting ftofix() is
>slightly more expensive because it does a range check, but nothing too
>complicated.
>
>
>--
>Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
>"Pigs use it for a tambourine" - Frank Zappa
- Raw text -