|
|
|
|
|
by nullc
702 days ago
|
|
When performing integer "division" of x by y, you're finding a solution {q,r} to the equation y * q = x - r. When y=0 any choice of q works, and using 0,x is a perfectly reasonable and intuitive way of defining things. Computer integers aren't the real numbers you learned about in gradeschool. INT_MAX+1 is not greater than INT_MAX. :) x/0 = program explodes is also a justifiable choice. It is not however more or less fundamentally correct than making the result 0. Floating point division by zero doesn't (typically) crash programs the way integer division by zero does (it typically returns a NaN-- and the programmer is free to turn nans to zeros if they like :)). |
|
Why would anyone think computer integers are real numbers? Anyone who's given it a modicum of thought will know intuitively they're a subset of "real life" integers, not reals.
>using 0,x is a perfectly reasonable and intuitive way of defining things.
I would argue it's neither reasonable nor intuitive. If you want to create some special data type then have at it, but if the behavior of `int` doesn't approximate the behavior of IRL integers, call your data type something else.