[fpc-pascal] Division by Zero: EDivByZero and EZeroDivide

Aleksa Todorovic alexione at gmail.com
Sun Oct 18 19:32:03 CEST 2009


On Sun, Oct 18, 2009 at 18:49, Jorge Aldo G. de F. Junior
<jagfj80 at gmail.com> wrote:
> Wouldnt a NaN (Not a number) be more "matematically correct" result (I saw
> that on an old book about i387)
>
> Matematically division by zero is an "mathematical impossibility", so NaN
> would be more logical
>
> Is there a way to deal with NaN's and other i387 (and similars) conventions
> directly in Pascal ?

Take a look at SysUtils, functions IsNaN, IsInfinite.

>
> 2009/10/18 Tom Verhoeff <T.Verhoeff at tue.nl>
>>
>> On Sat, Oct 17, 2009 at 01:57:28PM +0200, Bart wrote:
>> >
>> > Is there a reason why in fpc both floating point and integer division
>> > by zero raise an EDivByZero exception?
>> >
>> > See: http://docwiki.embarcadero.com/VCL/en/SysUtils.EZeroDivide
>> >
>> > SysUtils.EZeroDivide exception is raised when an application attempts
>> > to divide a floating-point value by zero.
>> > Note:  Integer divide-by-zero errors raise the SysUtils.EDivByZero
>> > exception.

Maybe because is more consistent to have one type for both exceptions
- when you see it, you know what it means. How could anybody make
distinction between EDivByZero and EZeroDivide without looking at
documentation?

>>
>> It would be nicer if one had the ability to make floating-point division
>> by zero return an IEEE 754 plus/minus infinity, without raising an
>> exception.  This is e.g. useful when one needs to evaluate rational
>> functions.  Without such an infinity, you need to make a nasty case
>> analysis, which furthermore depends on the rational function.
>>

There is function SetExceptionMask in SysUtils which you can use to
control which exceptions will be thrown at runtime. I haven't used it,
but looks like a good place to start...



More information about the fpc-pascal mailing list