P
Prateek R Karandikar
Jeff Relf said:Hi Karl Heinz Buchegger,
You asked,
" Where in the C++ standard is it mentioned that
dividing by 0 does not trigger an exception with
release compiled code. "
For VC 6 release-complied code,
a floating point divide-by-zero simply returns an overflow.
Which can then simply be checked using _isnan( float ).
I just checked integers ... They will hang your code ...
forcing you to kill it.
Now, ignoring standards for just one moment,
which response do you think was better behaved ?
ignoring standards? the Standard is the very document that defines the
language, and Standard C++ is the topic of this group. If you choose
to ignore the Standard, then it becomes off-topic for this group.
A. The one that had to be killed by hand.
B. The one that simply returned an overflow,
and which could then be checked using _isnan( float ).
Take your time answering this question,
I know how hard it is for you.
Division by zero invokes undefined behaviour, so any behaviour is ok.
Efficiency is very important for C++. Option A would probably be more
efficient. Option B tests the second operand of operator/ (for the
inbuilt usages) for equality to zero, each time you divide. So it is
inefficient. If you are willing to check for overflow after the
division, why not simply check *before* the division whether the
second operand is zero or not? BTW, your scheme involves 2 checks: the
system checks once when you divide, and returns overflow on zero, and
then you check later for overflow. Instead, why not check just once
before the division?
After you answered that question,
I might answer your question
about IEEE floating point standards.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!