How different programming languages handle divisio

2020-03-24 04:40发布

Perhaps this is the wrong sort of question to ask here but I am curious. I know that many languages will simply explode and fail when asked to divide by 0, but are there any programming languages that can intelligently handle this impossible sum - and if so, what do they do? Do they keep processing, treating 350/0 as 350, or stop execution, or what?

10条回答
何必那么认真
2楼-- · 2020-03-24 05:05

The INTERCAL standard library returns #0 on divide by zero

查看更多
够拽才男人
4楼-- · 2020-03-24 05:08

The little-known Java programming language gives the special constant Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY (depending on the numerator) when you divide by zero in an IEEE floating-point context. Integer division by zero is undefined, and results in an ArithmeticException being thrown, which is quite different from your scenario of "explosion and failure".

查看更多
时光不老,我们不散
5楼-- · 2020-03-24 05:14

i'd be surprised if any language returns 350 if you do 350/0. Just two examples, but Java throws an Exception that can be caught. C/C++ just crashes (i think it throws a Signal that can probably be caught).

查看更多
登录 后发表回答