Why is 0 divided by 0 throwing an overflow error in VBA?

前端 未结 2 609
萌比男神i
萌比男神i 2020-12-11 01:55

Why is 0/0 throwing Overflow error in VBA, while in .Net languages it is simply a Division by 0 error?


E.g., in C#

相关标签:
2条回答
  • 2020-12-11 02:32

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/floating-point-division-operator

    Besides the obvious differences in implementation of languages and the way VBA handles division, MS Doc link above expands on the reasons for overflow exception , that if the operand data types are integer then it will throw Overflow exception (Last statement below)

    Alternatively there is \ division operator that checks the range for you and throws Division by zero exception

    0 讨论(0)
  • 2020-12-11 02:34

    Will try to summarize the answers from the comments:

    1. In VBA 0/0 throws an Overflow exception, because 0/0 is a specific case of division by 0. Thus, it is a good idea to throw a different exception than the standard Division by zero error.

    2. In VBA Evaluate("0/0") returns a Division by zero error, because Evaluate does not raise an error, it returns a Variant value with an error flag, and there is no "overflow" flag available.

    3. In VBA integer division 0\0 returns a Division by zero error, because the result should be an integer value and #IND is a floating point value. As far as #IND cannot be returned, it gives the next best thing - Division by zero error.

    More reading concerning 0/0 in other languages:

    • How to produce a NaN float in c?

    • VB.NET

    0 讨论(0)
提交回复
热议问题