cmp() on integers - is there guarantee of returning only +-1 or 0?

skip at pobox.com skip at pobox.com
Sun Mar 19 18:19:12 EST 2006


    Dmitry> doc says that it must be > 0, or < 0, but it seems that it
    Dmitry> returns +1 or -1. Can it be reliably used to get the sign of x:
    Dmitry> cmp(x, 0) like pascal Sign() function does?

Why not

    def sign(n):
        return n and n/abs(n) or 0

Skip



More information about the Python-list mailing list