3 ms·
7 / 2 = 3 is similarly nonsense. It's just more familiar. How about 5 - 8 = 0? Sensible result for the natural numbers. X + 7? Surely you meant addition modul
by JonChesterfield 2y ago
7 / 2 = 3 is similarly nonsense. It's just more familiar.
How about 5 - 8 = 0? Sensible result for the natural numbers.
X + 7? Surely you meant addition modulo 2^64.
What's the count leading zeros on zero? Is it zero, 64, random noise found in a register?
What's X shifted by word size? Zero? Minus one? X?
These are all choices. Some are familiar. But knowing integer divide zero is wrong is a tenant of faith.
- linearrust 2y ago> 7 / 2 = 3 is similarly nonsense. It's just more familiar. It isn't nonsense. 7/2 represents a real number. You can round a real number up or down. So you can round 3.5 to 3. 7/0 doesn't represent a real number. It doesn't even make sense to do anything to an undefined number.
- JonChesterfield 2y agoHow about a rational number? Why not a complex number? That you especially like the real numbers is particularly unfortunate when they are so poorly represented in essentially all programming languages.
- linearrust 2y ago> How about a rational number? All rational numbers are real numbers. > Why not a complex number? What? > That you especially like the real numbers is particularly unfortunate It's not a matter of me liking or disliking real numbers. It's just that the topic at hand is about real numbers. > when they are so poorly represented in essentially all programming languages. Not essentially all programming languages. In every single one. It's the nature of real numbers. It's also not just 'programming languages', it's hardware as well.
- bee_rider 2y agoSure, why have our operators have any connection to what they conventionally mean in math at all, right? I think the result of 5 - 8 should be a linked list.
- lmm 2y ago> 7 / 2 = 3 is similarly nonsense. Indeed, which is why decent languages don't do that. Different symbol like // for truncating division if that's what you want. > How about 5 - 8 = 0? Sensible result for the natural numbers. Nah. Similarly, don't call that operation -; - underflowing should be an error. > X + 7? Surely you meant addition modulo 2^64. Surely you didn't. If your language does that, get a better language. > What's the count leading zeros on zero? What's the "count leading zeros" on anything? Numbers don't have leading zeroes (or rather, a number with leading zeroes is equivalent to one without them). > What's X shifted by word size? Zero? Minus one? X? No, it's X shifted by word size. (Which is a value bigger than a word, sure). If you want weird bit-twiddly operations because they're what your hardware implements efficiently, by all means have them. But don't use the standard mathematical symbols for operations that don't have the standard mathematical behaviour. And that includes a "divide" operation that silently accepts 0 and returns some normal value.
- nsguy 2y agoI think the OP's point was that '/' is not a mathematical divide anyways. Sure, we can remove '/' and make that a happy face emoji but I don't think that changes the premise here. Making sure you don't divide by zero is just one of those things programmers learn... like making sure you don't derefence null or go beyond the size of your array, or overflowing... not clear to me that masking that helps, maybe the ship wouldn't strand but instead it'd run into a bridge.
- lmm 2y ago> Sure, we can remove '/' and make that a happy face emoji but I don't think that changes the premise here. Disagree. The whole point of calling it '/' is to tell the reader that it is mathematical division. > Making sure you don't divide by zero is just one of those things programmers learn... like making sure you don't derefence null or go beyond the size of your array, or overflowing... not clear to me that masking that helps, maybe the ship wouldn't strand but instead it'd run into a bridge. In all of those cases it's much better for your program to explode quickly and loudly than silently continue (e.g. you'd hope dereferencing null triggered an error rather than just letting your program continue). Defining x/0 = 0 is masking the error and continuing, which tends to lead to corrupt data and silent wrong results.