Since most numerical code today is in libraries, and libraries can't go setting the CSR because different libraries might conflict, etc., it is really a huge issue. Please someone just change this globally, by fiat. Microsoft? Linux? WASM? PLEASE???
-
Show this thread
-
Maybe somebody has already, and if so, I commend you. But as far as I can tell so far, everybody still defaults to _crashing the program_ when it divides by zero.
2 replies 0 retweets 12 likesShow this thread -
Replying to @cmuratori
Maybe I'm misunderstanding: what would you like the following code to do? int x = 2 / 0; cout << x;
1 reply 0 retweets 0 likes -
Replying to @JaneSchwartz100
It's not what I would like it to do, it's what it _does_ do provided you set MXCSR properly (or the equivalent on other CPUs). With div-by-zero/underflow turned off, and flush-to-zero turned on, 2/0 = 0. So your code would print 0.pic.twitter.com/ju2q6BIfv5
1 reply 0 retweets 1 like -
Replying to @cmuratori @JaneSchwartz100
The only reason it _doesn't_ do that by default is because - for some truly bizarre reason - the default setting for MXCSR is to fault on divide by zero. Even though that is basically never what you want, unless you are debugging.
1 reply 0 retweets 1 like -
Replying to @cmuratori
Shouldn't we want to crash hard with errors like these, instead of letting them go unnoticed silently?
3 replies 0 retweets 2 likes -
Replying to @JaneSchwartz100 @cmuratori
Even for errors, crashing the program is usually a bad way to handle things. But often times it's not an error at all
1 reply 0 retweets 0 likes -
The question is: how often? 90% of the time or 10% of the time? I personally never had case when x/0 was not due to bug in my code.
2 replies 0 retweets 1 like -
Even if it was 100% bugs, you'd still want to not have it crash when you release to end users. If flush to zero was default, your debug build could still crash on divide by zero if that's what you want. The debug build should be the one with more conditionals, not release
2 replies 0 retweets 0 likes -
If there's a bug in the app that made it to the user, I'd prefer the user report to me the app crashed rather than get wrong results.
1 reply 0 retweets 0 likes
What I'm trying to point out, though, is that _they are not bugs_. Yes, you _can_ write a divide by zero that is a bug; but you can also write a divide by zero that works properly, and in most cases, it is actually trivial to write the code this way.
-
-
Replying to @cmuratori @JaneSchwartz100 and
Most code that divides can be written so that divide-by-zero-equals-zero would result in the _correct_ behavior for the program.
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.