3 ms·
> 1/2 = 0 is mathematically incorrect. 1/2 = 0.5 is mathematically correct. Those are two different functions, and both are "mathematically correct". The notat
by khedoros 10y ago
> 1/2 = 0 is mathematically incorrect. 1/2 = 0.5 is mathematically correct.
Those are two different functions, and both are "mathematically correct". The notation is the problem. The former operation isn't specifying the division operator, it's specifying an integer division operator.
- infogulch 10y agoSo "/" actually represents two completely different functions, and to disambiguate between them you inspect the types of the operands. That works OK in statically typed languages, but Python is dynamically typed. There's no way to specify which operator you want without verbosely type-casting before each use. So Python 3 fixes this by separating the two different functions to use different operators: "/" for Real (float) division, and "//" for integer division. Problem solved.
- khedoros 10y agoI agree with anything that you just said, and that's not the portion of the previous post that I had a problem with. The Python3 disambiguation is a nice way to handle the former ambiguity.
- deleted 10y ago[deleted]
- jhall1468 10y agoI'm aware that they are different functions, but I strongly feel they were poorly implemented. / is a mathematical symbol in addition to being a function in Python, but in Python it is implemented in a different way that is mathematically (but not pragmatically) incorrect.
- khedoros 10y ago> I strongly feel they were poorly implemented. I'll agree with this. In the context of Python, the behavior is surprising. > but in Python it is implemented in a different way that is mathematically (but not pragmatically) incorrect. I disagree with this statement, for pedantic reasons. I wouldn't expect someone to use "/" in the context of standard arithmetic to mean integer division without explicitly redefining it, but redefining it would certainly be "mathematically correct". Look at the notation for Galois fields. That redefines all of the standard operators to work within a field of limited elements, and I'd consider the use-case to be comparable.
- jhall1468 10y ago> Look at the notation for Galois fields. That redefines all of the standard operators to work within a field of limited elements, and I'd consider the use-case to be comparable. Finite fields define standard operators because using mathematical operations two sets of fields is ambiguous. So I don't consider that "redefining", in the sense that they are being used unexpectedly, I consider that just defining how to use them in this special use case. Whereas Python is defining / to do two operations: divide and truncate. I call that redefining because there's a certain expected outcome if you've had elementary math, and that's not what Python delivers.