3 ms·
I kind of get what you are saying syntactically, but the semantics are weird to me as the C version is only defined for integers in the first place so saying th
by saurik 5y ago
I kind of get what you are saying syntactically, but the semantics are weird to me as the C version is only defined for integers in the first place so saying that the operator is truncating something is an awkward mental model.
- masklinn 5y ago> I kind of get what you are saying syntactically, but the semantics are weird to me as the C version is only defined for integers Why? Mathematically, dividing two integers yields a real. If you want the result to be an integer, you need to define some rounding operation on the real result to produce an integer. That is the source of the divergence between C and Python here, C rounds by truncation (towards 0), Python rounds by flooring (towards -inf).
- saurik 5y agoOh, I'm dumb. Sorry. (I got the terms for quotient, dividend, and divisor mixed up.)
- masklinn 5y ago> Oh, I'm dumb. We both know that's not true. > Sorry. (I got the terms for quotient, dividend, and divisor mixed up.) No big, brainfarts happen.
- DonHopkins 5y agoJust don't divide by zero. That's how you get black holes!
- dragonwriter 5y ago> Mathematically, dividing two integers yields a real Rational, more specifically.
- desio 5y ago> Mathematically, dividing two integers yields a real not true. if you define 'divide' as inverse multiplication over the reals then that is closer to being true (zero is an integer, dividing an integer by zero doesn't yield a real). in that case every real can be expressed as n = a/b where a and b are integers and b != 0 then yes n is a real. But 'divide' could just as well be defined along the lines of divisibility in number theory (the study of integers) where every integer can be expressed as n = q*b + r, where n,q,b,r are all integers and r >= 0 > b. then you could say that n divide b = q, with r as remainder, and n mod b = r. These are my preferred definition of mod and integer division.
- LudwigNagasena 5y agoMathematically, Euclidean division of two integers yields an integer. You don't need to define reals or rounding. Children learn how to do it before they learn about rational numbers.
- dotancohen 5y agoI invite you to ask your child how he would share three cookies with you. I've been asking variations of that question to all three of my children since they could talk. Of interesting mathematical consequence, each of my children converged on the same solution at different ages. Them: three cookies. Daddy: zero cookies.
- glandium 5y agoIf it's not truncating, how do you describe its behavior when e.g. an odd number is divided by 2?
- saurik 5y ago(Read the rest of the thread and look for my username.)