Hi Harry_Kewell;
The statement, If y <> (x / y) Then, will not throw an error of divide by zero when y is equal to zero because the / operator uses floating point numbers for x and y, widening the values of x and y to data type Double, and handles the return as a constant value of positive infinity if x is positive and negative infinity when x is negative and the y vale was a zero. This result differs from integer division where ( x \ y ) will return a divide by zero error when y is zero.
Fernando
Main Topics
Browse All Topics





by: SanclerPosted on 2006-09-23 at 02:42:33ID: 17583180
Have a look at this
/en-us/lib rary/25bsw c76.aspx
http://msdn2.microsoft.com
particularly this bit
>>
Integral (signed or unsigned)
Attempted conversion back to integral type throws OverflowException because integral types cannot accept PositiveInfinity, NegativeInfinity, or NaN
<<
My analysis is that the line
If y <> (x / y) Then
does not require the term (x / y) to be converted back to an integer type for the <> test to be applied. It is sufficient to compare y - as an OBJECT - with (x / y) - as an OBJECT.
Is it consistent with that analysis (although I do not claim that it proves that it is true) that changing that line to
If y <> CInt(x / y) Then
does throw an error.
Roger