-1

I am using this function from the GMP arbitrary precision arithmetic library:

Function: void mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t a, const mpz_t b)

Set g to the greatest common divisor of a and b, and in addition set s and t to coefficients satisfying a*s + b*t = g. The value in g is always positive, even if one or both of a and b are negative (or zero if both inputs are zero). The values in s and t are chosen such that normally, abs(s) < abs(b) / (2 g) and abs(t) < abs(a) / (2 g), and these relations define s and t uniquely. There are a few exceptional cases:

If abs(a) = abs(b), then s = 0, t = sgn(b).

Otherwise, s = sgn(a) if b = 0 or abs(b) = 2 g, and t = sgn(b) if a = 0 or abs(a) = 2 g.

In all cases, s = 0 if and only if g = abs(b), i.e., if b divides a or a = b = 0.

If t is NULL then that value is not computed. 

I do not need the values of 'g' or 't' and would not like to create variables for the sole purpose of passing to this function. What can I do to pass something like a placeholder to this specific function, and how can I do this in c++ in general?

Saul Femm
  • 17
  • 3
  • It doesn't work this way. If a library function requires a parameter, it must be specified. It's possible that a given parameter to a library function is optional, if so the library's function's documentation will explain what value to pass for that parameter, in that case. Check the library function's documentation for more information. – Sam Varshavchik Nov 13 '16 at 01:30
  • Of course I understood this to be true for input parameters, but I thought I may be able to use something arbitrary for output parameters I didn't need. Unfortunate. Thank you! – Saul Femm Nov 13 '16 at 01:40
  • "If t is NULL then that value is not computed" so at least for that one, your answer is trivial. If you want to skip updating g, you can look at the code for `mpz_gcdext` and adapt it to your need, calling the underlying `mpn_gcdext` yourself. Although it is not documented, you can apparently also pass s=NULL to the function. You could send a patch to GMP that also allows g=NULL... – Marc Glisse Nov 13 '16 at 09:07
  • The next version of GMP will allow you to call `mpz_gcdext(NULL, s, NULL, a, b);`. – Marc Glisse Nov 26 '16 at 14:53

1 Answers1

-1

You might overload the function.

void mpz_gcdext (mpz_t s, const mpz_t a, const mpz_t b)
{
    mpz_t g, t;
    // initialize g and t as needed
    mpz_gcdext(g, s, t, a, b);
}

Does that help?

Waxrat
  • 2,075
  • 15
  • 13
  • The point was to avoid declaring and initializing variables that I didn't need. This would still do that. – Saul Femm Nov 13 '16 at 01:41
  • ok. If the mpz_gcdext function expects those arguments, then you must declare and initialize them. The overload would let you do that in just one place instead of having to do it everywhere you call mpz_gcdext, but you still need to do it somewhere. – Waxrat Nov 13 '16 at 02:02