logoalt Hacker News

godelskilast Monday at 12:35 AM1 replyview on HN

  > even if the code says something like `total /= 0`
In what context would this not be wrong?

I mean... it might run or compile but our best case scenario is what, javascript where it returns infinity? But I'd certainly take issue with any program where I saw an explicit division by zero. If you were just trying to create an infinity there's got to be a good explanation for doing it that way.


Replies

Buttons840last Monday at 11:49 PM

It could trigger an exception which is caught elsewhere, or round the number to Inf or -Inf. It's a "clever" (aka, stupid) way to do these things, but it might not technically be wrong. It is possible to have well behaved and reliable code doing such a thing, unlike UB in C++.