From: Jeff Weeks Newsgroups: comp.os.msdos.djgpp Subject: 16.16 fixed point math multiply (overflow problems) Date: Wed, 30 Jul 1997 14:59:13 -0400 Organization: Code X Software Lines: 28 Message-ID: <33DF8F01.58BCC37C@execulink.com> NNTP-Posting-Host: ppp35.saturn.execulink.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Yeah, yeah, I know... Fixed point math is easy. And I've used it many times... but 24.8, not 16.16. I just recently wrote a tiny 16.16 fixed point math class which doesn't work well at all. My multiply function overflows everytime, and it's obvious why. Here's what I do: (x * y) >> 16; Obviously anything over 1 * 1 (65536 * 65536) will result in an overflow, even in a 32-bit register. I'm wondering what the best technique is to multiplying in a 16.16 fixed point format? Secondly... Michael Abrash's multiply code seems to do EXACTLY what I do!?! How can he publish this code (Zen of Graphics Programming) when it obviosly doesn't work in all (most) cases! Or am I missing something? Thanks a lot, Jeff -------------------------------------------- - Code X Software - Programming to a Higher Power email: mailto:pweeks AT execulink DOT com web: http://www.execulink.com/~pweeks/ --------------------------------------------