nordlow / gmp-d

D-language high-level wrapper for GNU MP (GMP) library
14 stars 6 forks source link

Add invert function (mpz_invert) #7

Closed basiliscos closed 6 years ago

nordlow commented 6 years ago

Thanks!

nordlow commented 6 years ago

Made a couple of optimizations of invert().

nordlow commented 6 years ago

We should add an assert that your comment

Parameter `exp` must be positive.

is fulfilled. But there is no exp parameter. Do you mean base or mod or both?

I tried changing the sign of mod but that doesn't have any effect on the tests. And changing the sign of base doesn't trigger the assert(success >= 0) but gives a different answer. When does this operation fail, then?

basiliscos commented 6 years ago

Parameter exp must be positive.

Oopps, sorry, please remove that copy-paste line :)

. But there is no exp parameter. Do you mean base or mod or both?

neither. They both should be non-zero, but can be negative, AFAIK.

I tried changing the sign of mod but that doesn't have any effect on the tests. And changing the sign of base doesn't trigger the assert(success >= 0) but gives a different answer. When does this operation fail, then?

Try 15.Z.invert(25.Z)

nordlow commented 6 years ago
  1. Are base and mod good namings?
  2. A zero base returns a zero. Is this wrong?
basiliscos commented 6 years ago

Are base and mod good namings?

I think so. It is (symbolicallty) equivalent base.invert(mod) ==base.powm(-1, mod).

A zero base returns a zero. Is this wrong?

Well, yes. cz, 0.powm(0, N) != 1

nordlow commented 6 years ago

Great, then everything should be commited on master as you wanted.

basiliscos commented 6 years ago

Thank you! Please, upload the new version to http://code.dlang.org/

nordlow commented 6 years ago

I pushed tag v0.1.1 to github. Is that sufficient?

nordlow commented 6 years ago

Apparently ;)