www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/15/13:47:17

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Definiton of fixed in Allegro
Date: Thu, 15 Jan 1998 08:32:27 +0000
Organization: None
Distribution: world
Message-ID: <250eqCAbmcv0EwUx@talula.demon.co.uk>
References: <34BD6A0D DOT E82119F5 AT rogers DOT wave DOT ca>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 30
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019