Mail Archives: djgpp/1997/02/20/10:34:10
From: | Jeff Weeks <pweeks AT execulink DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | fixed point math: SOLUTION!!!
|
Date: | 20 Feb 1997 03:18:28 GMT
|
Organization: | Internet News Service
|
Lines: | 42
|
Message-ID: | <5egfq4$3pk@nr1.toronto.istar.net>
|
NNTP-Posting-Host: | news.linkd.net
|
Mime-Version: | 1.0
|
XPident: | Unknown
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
I don't know if anybody remembers but I was having some trouble with
fixed point math a while ago. I asked a quesion a while ago and many
people pointed out that I had my shifts going the wrong way. However,
this was not the problem. Many of you will probably laugh at this but
I'm going to present my solution just so others don't fall into the same
ditch I did... it's not fun! :)
Anyway, I had a (slow... only for debug purposes) putpixel macro...
#define putpixel(x,y,c) \
_farpokeb(_dos_ds, 0xA0000+y*320+x, c);
and then later in the program I was doing something like:
putpixel(x>>8,y>>8,c);
well, folks... this expands into:
_farpokeb(_dos_ds, 0xA0000+y>>8*320+x>>8, c);
well, this is definitly not the desired result. Therefore, my simple
solution... "WHENEVER using fixed point math make profuse use of
brackets!!!" Like the following:
#define putpixel(x,y,c) \
_farpokeb(_dos_ds, 0xA0000+(y)*320+(x), (c));
This will ensure your code works as expected.
Like I said... some may laugh... but's it's a real bitch when bugs like
these get into your program and haunt you so I'd just like to present
this solution as a, sort of, preventive aid.
Hope that helps atleast one person,
Jeff Weeks
--------------------------------------------
- Code X Software -
Programming to a Higher Power
email: mailto:pweeks AT execulink DOT com
web: http://www.execulink.com/~pweeks/
--------------------------------------------
- Raw text -