Re: [OT] Fixed Point Math ( was Re: semicircle )

Search this archive.

From: Jim Jackson (jj@scs.leeds.ac.uk)
Date: Wed 01 Dec 1999 - 11:28:30 IST


On Wed, 1 Dec 1999, Clive Crous wrote:

> ok, last night i went and attempted to get that semicircle algorith of mine
> working.
> i discovered 3 problems.
>     1>    i need to research type casting ;-)
>     2>    it'll draw a semi circle with the "curve" being 1280 degrees or
> LESS
>     3>    Fixed point math doesn't work in c ??????????????
> 
> I used to do a lot of graphical type programming using pascal/assembler and
> everything i did was *speed* orientated.  For this reason I got quite used
> to using fixed point math in my calculations instead of relying on the FPU
> to do the grunt work.
> 
> here's a quick lil snippet of my program, and the results it gave ..
> ----------------------------------------------------------------
> #define FIXED_B 16
> #define FIXED_M 1<<FIXED_B

#define FIXED_M (1<<FIXED_B)

> <snip>
> int xp,cx;
> <snip>
> cx=xp/FIXED_M;

after substitution of FIXED_M this becomes

 cx=xp/1<<FIXED_B;

i.e. divide xp by 1 then left shift  16 !!!

The brackets make it

 cx=xp/(1<<FIXED_B);

making the order of the operators correct.

> fprintf(stdout," %d = %d / %d\n",cx,xp,FIXED_M);
> <snip>
> ----------------------------------------------------------------
> output gives:
> 
> 2808465 = 2808465 / 65536
> or
> -2808465 = 2808465 / 65536
> or
> -65536 = 2808465 / 65536
> 
> ?????????? wtf ?
> 
> cx always seems to be ((xp)||(-xp)||(FIXED_M)||(-FIXED_M))
> ----------------------------------------------------------------
> 
> could some1 please tell me what i've done wrong ?
> 
> thanks in advance
>     Clive
> 
> 


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:22 IST