[issue12211] math.copysign must keep object type.
umedoblock umedobl...@gmail.com added the comment: abs() behavior show below. type(abs(-1)) class 'int' type(abs(-1.0)) class 'float' we should fix this problem if write Return abs(x) with the sign of y I'd like to try this problem if need fix. I'm going to attach the patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Mark Dickinson dicki...@gmail.com added the comment: How about something like: Return a float with the magnitude of x but the sign of y.? The behaviour of math.copysign with respect to non-float inputs matches that of almost all the other math module functions: integer arguments are first converted to floats, and then the underlying libm function applied. I'm not convinced that changing the behaviour of copysign to produce integer results for integer argument would be a good idea. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Terry J. Reedy tjre...@udel.edu added the comment: Return a float with the magnitude of x but the sign of y. This appears to describe both current behavior and what I believe was the intention. I would go with a doc patch based on this. umedoblock, go ahead and make one. It occurred to me, also, that as currently written, copysign 'should' return the type of the first arg. In C89, and I suspect in Python 1.0, all math functions return double (Python float). Like Mark, I am more inclined to change the doc than the code. 1. One use of copysign is to give a correctly signed 0.0. This does not apply to ints, where 0 is always unsigned. I do not know of any use of copysign in number (count/int) theory. (There could be, of course.) 2. icopysign(-1,0) == +1 (sign added for emphasis), whereas I believe that for ints, the answer should be -1, as 0 has no sign. def icopysign(j,k): if (j 0) and (k 0) or (j 0) and (k 0): return -j return j for j,k,i in ((1,1,1), (1,-1,-1), (-1,-1,-1), (-1, 1, 1), (1,0,1), (-1,0,-1)): assert icopysign(j,k) == i, (j,k,i) This would certainly be up for debate if we changed the code, but there should be no difference in outputs for same value inputs. (This principle is the reason for / and //.) So lets leave copysign as a function defined on floats with inputs coerced to float if needed. Anyone who needs it for ints can define it for (-1,0) according to their need. -- assignee: - docs@python components: +Documentation -Library (Lib) nosy: +docs@python stage: - needs patch versions: +Python 2.7, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
umedoblock umedobl...@gmail.com added the comment: I made the patch. But it cannot pass testCopysign(). math.copysign(1, -0.) returns 1. I hope to return -1. But I don't know how to realize -0. as negative value. Please help me. -- components: +Library (Lib) -Documentation keywords: +patch versions: -Python 2.7, Python 3.3 Added file: http://bugs.python.org/file22249/math_copysign.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Changes by umedoblock umedobl...@gmail.com: Removed file: http://bugs.python.org/file22249/math_copysign.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Changes by umedoblock umedobl...@gmail.com: Added file: http://bugs.python.org/file22250/math_copysign.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Changes by umedoblock umedobl...@gmail.com: Removed file: http://bugs.python.org/file22250/math_copysign.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Terry J. Reedy tjre...@udel.edu added the comment: umedoblock: David, Mark, and I agree that this should be a doc issue, and so I suggested a DOC patch. So I do not know why you are screwing around with the code, or what you are trying to do with it, or why you are messing around with the version headers or why you think this is a 3.2 only issue. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
umedoblock umedobl...@gmail.com added the comment: sorry. I fix my bug. but this patch contain new fail... math.copysign(-1., 0.) returns 1. -- Added file: http://bugs.python.org/file22251/math_copysign.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
umedoblock umedobl...@gmail.com added the comment: I attached DOC patch. I misunderstand ? Sorry... I think that go ahead and make one means I shuold make the source patch. I use just Python3.2. I didn't use Python 2.x, 3.0 and 3.1 in my programming life. Therefore I reported version 3.2. I should the versions to 3rd party ? -- Added file: http://bugs.python.org/file22254/math.rst.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Terry J. Reedy tjre...@udel.edu added the comment: As with all the math docs, 'x' refers to the value, not the object with the value. However, Return abs(x) with the sign of y is, to me, clearer and more accurate. Both doc string and doc chapter should get any modification. -- nosy: +terry.reedy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
New submission from umedoblock umedobl...@gmail.com: I expected return int if I gave x as integer to copysign. I encounterd two problems. I'd like to fix this problems. but I can't come up with nice idea. therefore I just report for you. one: import math a = [0, 1, 2, 3] i = 1 i_copysign = math.copysign(i, -1) a[i_copysign] Traceback (most recent call last): File stdin, line 1, in module TypeError: list indices must be integers, not float two: n = 10 ** 20 math.copysign(n + 1, 1) == n + 1 False -- components: Library (Lib) messages: 137226 nosy: umedoblock priority: normal severity: normal status: open title: math.copysign must keep object type. type: behavior versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12211] math.copysign must keep object type.
R. David Murray rdmur...@bitdance.com added the comment: Except when explicitly noted otherwise, all return values are floats. On the other hand, copysign says return x with the sign of y, which certainly sounds like it is preserving x, not creating a new float. So at the least there is a doc issue, I think. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12211 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com