[Tutor] why can't I find a function that givesme the sign of an integer?
Rinzwind
w.damen at gmail.com
Fri Jan 27 07:40:17 CET 2006
> On 1/26/06, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
> >> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0.
> > Well, the cmp() function does this if you compare the number to 0:
>
> Neat trick Orri, I'd never have thought of that one :-)
>
> Alan G.
Glad I could help :=)
On 1/26/06, Kent Johnson <kent37 at tds.net> wrote:
> Orri Ganel wrote:
> > Rinzwind wrote:
> >
> >> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0.
> > Well, the cmp() function does this if you compare the number to 0:
> >
> > >>> cmp(-34,0)
> > -1
> > >>> cmp(0,0)
> > 0
> > >>> cmp(23,0)
>
> One caution: this behaviour doesn't seem to be required, the docs allow
> any positive or negative integer:
> cmp( x, y)
> Compare the two objects x and y and return an integer according to
> the outcome. The return value is negative if x < y, zero if x == y and
> strictly positive if x > y.
>
> So this behaviour might differ between Python versions.
>
> Kent
Now you lost me.
Eh you mean to say that in next Python versions someone could decide
to change cmp(x,0) to another meaning? I bet my countryman (I'm from
Holland too ;-) ) will veto that! Or else I'll pay him a visit :D
More information about the Tutor
mailing list