From: Jedediah Smith Newsgroups: comp.os.msdos.djgpp Subject: Integer division causes strange behavior Date: Sun, 05 Jul 1998 06:27:42 -0700 Organization: Interlog Internet Services Lines: 30 Message-ID: <359F7F4E.3845@interlog.com> NNTP-Posting-Host: 209-20-0-182.dialin.interlog.com NNTP-Posting-Time: 5 Jul 1998 07:24:35 GMT 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 A program I am writing uses this function to round toRound up to the nearest multiple of factor. The function is called thousands of times and then later on a huge amount of text (about 500k) is output to stdout using the cout class. While outputting all that text, sometimes right in the middle of a cout call, the program aborts with some sort of protection fault and then rhide aborts with an 'FPU not present' fault. The weird thing is, I have narrowed the problem down to the line marked with an arrow in the code below. If I take that line out, the program works fine. I have also tried other alogritms that use / instead of % and I even tried using the div() function and they all do the same thing. My program doesn't use any floating point math so I really have no idea where that rhide error is coming from. unsigned RoundUp(unsigned toRound, unsigned factor) { --> unsigned modFactor = toRound % factor; unsigned ret = toRound; if (modFactor != 0) ret += factor-modFactor; return ret; } -- ..... :edediah :.: