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
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
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
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
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
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
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?
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
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)
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
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
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
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
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
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
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
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
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
18 matches
Mail list logo