From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Definiton of fixed in Allegro Date: Fri, 16 Jan 1998 19:26:15 +0000 Organization: None Distribution: world Message-ID: References: <34BD6A0D DOT E82119F5 AT rogers DOT wave DOT ca> <250eqCAbmcv0EwUx AT talula DOT demon DOT co DOT uk> <34bf243e DOT 9083522 AT news DOT magna DOT com DOT au> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 26 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk riotnrrd writes: >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? Sure. It is very easy to figure out what you can and can't do with a fixed point number, once you work out the math behind it. To store a fractional values in what is really an integer data type, fixed point routines simply scale the value up by some multiplier, which in the case of a 16.16 format is 2^16 = 65536. If you call this factor f, you would represent the fractional value x as the integer x*f, and y as y*f. After which it is just basic algebra... x*f + y*f = (x+y)*f - correct, so you can add them x*f - y*f = (x-y)*f - correct, so you can subtract them x*f * y*f = (x*y)*f^2 - wrong! multiplication is different x*f / y*f = x/y - wrong! division is also special The fact that you have scaled up the values won't make any difference when you want to compare or negate them, so it is safe to do that with normal integer operators. -- 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