Pergunta

I need maximum performances using GMP and I wonder whether there is a better way to compute the absolute value of the difference of two numbers. Currently I use:

mpz_sub(x, a, b);
mpz_abs(x, x);

Is there a most efficient way to do that ?

Foi útil?

Solução

Your code should already be close to optimal. When the source and destination are the same, mpz_abs takes constant time: it does not read the big number and only performs a trivial operation on the sign.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top