I need to get the absolute value of an mpz
object in GMPY2
but I cannot find any function like abs()
. How can this be done?
mpz objects provide __abs__
, and so the ordinary abs
works:
>>> gmpy2.mpz(3)
mpz(3)
>>> abs(gmpy2.mpz(3))
mpz(3)
>>> gmpy2.mpz(-3)
mpz(-3)
>>> abs(gmpy2.mpz(-3))
mpz(3)