質問

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 ?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top