Re: Negative integers

2008-08-21 Thread Uwe Schmitt
On 20 Aug., 23:38, johnewing <[EMAIL PROTECTED]> wrote: > I am trying to figure out how to test if two numbers are of the same > sign (both positive or both negative).  I have tried > > abs(x) / x == abs(y) / y > > but that fails when one of the numbers is 0.  I'm sure that there is > an easy way t

Re: Negative integers

2008-08-21 Thread Mikael Olofsson
Derek Martin wrote: Zero is a problem, no matter how you slice it. I definitely agree with that. Depends on the the real problem that is behind the OP:s question. Zero can be considered positive or negative (mathematically, 0 = -0). I've read quite a few articles written by mathematician

Re: Negative integers

2008-08-20 Thread eliben
On Aug 21, 1:30 am, Ethan Furman <[EMAIL PROTECTED]> wrote: > nntpman68 wrote: > > johnewing wrote: > > >> I am trying to figure out how to test if two numbers are of the same > >> sign (both positive or both negative).  I have tried > > >> abs(x) / x == abs(y) / y > > >> but that fails when one of

Re: Negative integers

2008-08-20 Thread johnewing
I managed to change my dataflow so that an earlier test rules out the possibility of a zero there. Still, thank you for the fast answers, this is my first time using the forum. Hopefully I will be able to be on the question answering end before too long. thanks again, john -- http://mail.python.o

Re: Negative integers

2008-08-20 Thread Derek Martin
On Wed, Aug 20, 2008 at 02:38:11PM -0700, johnewing wrote: > I am trying to figure out how to test if two numbers are of the same > sign (both positive or both negative). I have tried > > abs(x) / x == abs(y) / y Zero is a problem, no matter how you slice it. Zero can be considered positive or

Re: Negative integers

2008-08-20 Thread John Machin
On Aug 21, 7:46 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > johnewing wrote: > > I am trying to figure out how to test if two numbers are of the same > > sign (both positive or both negative). I have tried > > > abs(x) / x == abs(y) / y > > > but that fails when one of the numbers is 0. I'm su

Re: Negative integers

2008-08-20 Thread Ethan Furman
nntpman68 wrote: johnewing wrote: I am trying to figure out how to test if two numbers are of the same sign (both positive or both negative). I have tried abs(x) / x == abs(y) / y but that fails when one of the numbers is 0. I'm sure that there is an easy way to do this. Any suggestions?

Re: Negative integers

2008-08-20 Thread nntpman68
Hi, Dan's solution is probably the clearest. Just out of curiousity:. How would you in your program's context like 0 to be treated. should it be treated as a positive number or should it be treated as a case part. my suggestion a*b > 0 for example wouldn't work if you want 0 to be treated as

Re: Negative integers

2008-08-20 Thread Christian Heimes
johnewing wrote: but that fails when one of the numbers is 0. I'm sure that there is an easy way to do this. Any suggestions? For the not-so-distant future: Python 2.6 and 3.0 have a new function "copysign" in the math module. I added it during the revamp of the math module. copysign(x, y)

Re: Negative integers

2008-08-20 Thread nntpman68
Hm, It seems my previous reply got lost. if a*b > 0: print "same sign" else print "different sign" johnewing wrote: I am trying to figure out how to test if two numbers are of the same sign (both positive or both negative). I have tried abs(x) / x == abs(y) / y but that f

Re: Negative integers

2008-08-20 Thread Dan Stromberg
On Wed, 20 Aug 2008 14:38:11 -0700, johnewing wrote: > I am trying to figure out how to test if two numbers are of the same > sign (both positive or both negative). I have tried > > abs(x) / x == abs(y) / y > > but that fails when one of the numbers is 0. I'm sure that there is an > easy way t

Re: Negative integers

2008-08-20 Thread Vlastimil Brom
2008/8/20 johnewing <[EMAIL PROTECTED]> > I am trying to figure out how to test if two numbers are of the same > sign (both positive or both negative). I have tried > > abs(x) / x == abs(y) / y > > but that fails when one of the numbers is 0. I'm sure that there is > an easy way to do this. Any

Re: Negative integers

2008-08-20 Thread Fredrik Lundh
johnewing wrote: I am trying to figure out how to test if two numbers are of the same sign (both positive or both negative). I have tried abs(x) / x == abs(y) / y but that fails when one of the numbers is 0. I'm sure that there is an easy way to do this. Any suggestions? (a < 0) == (b < 0

Negative integers

2008-08-20 Thread johnewing
I am trying to figure out how to test if two numbers are of the same sign (both positive or both negative). I have tried abs(x) / x == abs(y) / y but that fails when one of the numbers is 0. I'm sure that there is an easy way to do this. Any suggestions? Thanks -- http://mail.python.org/mailm

Re: Negative integers and string formating

2006-10-23 Thread Steven D'Aprano
On Mon, 23 Oct 2006 18:56:21 -0700, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> def display(**kwargs): >> fs = format(kwargs['argument']) >> return fs % kwargs > > def display(**kwargs): > fs = format(kwargs['argument']) > return fs % dict((x, abs(y)) for

Re: Negative integers and string formating

2006-10-23 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > def display(**kwargs): > fs = format(kwargs['argument']) > return fs % kwargs def display(**kwargs): fs = format(kwargs['argument']) return fs % dict((x, abs(y)) for x,y in kwargs.iteritems()) -- http://mail.python.org/mailman/listi

Re: Negative integers and string formating

2006-10-23 Thread Brett Hoerner
Steven D'Aprano wrote: > Are there any string formatting codes that will place a space between the > sign and the number? Not that I know of, why not use the absolute value (after checking if it is negative), In [1]: abs(-1) Out[1]: 1 -- http://mail.python.org/mailman/listinfo/python-list

Negative integers and string formating

2006-10-23 Thread Steven D'Aprano
Problem: I have an application where I need to print integers differently depending on whether they are positive or negative. To be more specific, I have to print something that looks like: "something + 1" "something - 1" Note the space between the sign and the number. If I didn't need that spac