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?
Asked
Active
Viewed 287 times
1

netik
- 1,736
- 4
- 22
- 45
1 Answers
1
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)

DSM
- 342,061
- 65
- 592
- 494