Date: Tue, 3 Feb 1998 18:23:01 -0800 (PST) Message-Id: <199802040223.SAA05007@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Eli Zaretskii , John Luebs From: Nate Eldredge Subject: Re: division by 0 Cc: djgpp AT delorie DOT com Precedence: bulk At 12:27 2/3/1998 +0200, Eli Zaretskii wrote: > >On 3 Feb 1998, John Luebs wrote: > >> 2) The only way (should be #1 now!!!). Make a divide function: >> float divide(float a, float b) >> { >> if(!b) return MAX_FLOAT; /* if you never use the maximum then this may >> work as "inf" */ >> else return a/b; >> } > >For floating-point code you don't need this at all, as x87 will do this >for you if you set it up to mask off all FP exceptions (see `_control87' >in the library). If you do that, you will automatically get Inf, which is >better than FLT_MAX, since the latter is a valid number. (DJGPP v2.02 >will set up x87 to mask all exception by default, btw.) Is there some portable way to say what kind of exceptions you want? Sometimes a program would want some masked (like if I use NaN's), but others not (if divide by 0 would be a bug in my code). `_control87' can obviously do this, but equally obviously it won't work on anything but a 386/7. > >But if you need to do the same for integer code, you cannot do it >easily. Obviously, replacing every division with a function call would >be terribly slow. You could make it inline, but it would still be some overhead. Nate Eldredge eldredge AT ap DOT net