On 2017-12-11 12:22 PM, Sean McAfee wrote:
Well, not really.  I don't think x %% 0 should return a Failure at all.

1 / 0 is an expression which can evaluate to no sensible value, so it makes
sense to fail there.  By the question "Is one divisible by zero?" has the simple
answer "No."

I strongly disagree with you.

First of all, the reason there is no sensible value is that the answer is BOTH "yes" and "no" at the same time, so you can't choose one. Zero DOES divide evenly into anything, and typically does so an infinite number of times. Bottom line, there is no good reason to answer either "yes" or "no" for zero.

There are three distinct kinds of answers to the question "is x evenly divisible by y":

1. When dividing x by y there are no leftovers (yes).
2. When dividing x by y there are leftovers (no).
3. When dividing anything by zero there is no sensible value (Failure).

It is very important to distinguish the above 3 cases.

The main use case of %% is to gate logic where if 2 numbers do evenly divide we do some particular arithmetic with the results and if they don't but it is a valid division then we do other particular arithmetic with the results.

The expression "x %% y" is to be equivalent to "(x % y) == 0)".

-- Darren Duncan

Reply via email to