Reputation: 119
I have point(x,y) and i want add another point. i write only formul, but i want getting function:
struct point {
mpz_t x;
mpz_t y;
};
point my_func(mpz_t x, mpz_t y) {
/..../
//lambda
mpz_sub(a, Y, y);
mpz_sub(b, X, x);
mpz_invert(c, b, P);
mpz_mul(b, a, c);
mpz_mod(f, b, P);
//point x
mpz_mul(a, f, f);
mpz_sub(b, a, x);
mpz_sub(c, b, X);
mpz_mod(d, c, P);
//point y
mpz_sub(a, x, d);
mpz_mul(b, f, a);
mpz_sub(c, b, y);
mpz_mod(e, c, P);
return (x, y);
}
It seems to me that this should not be difficult, but I have been driving all day. point gp = {x, y}; error: array must be initialized with a brace-enclosed initializer
I want only having a point (x, y) to get the next point at the output. it does not have to be a structure, I tried pair and tuple, it still does not help.
Upvotes: 0
Views: 221
Reputation: 119
really, why bother with something if i need to just change the values of x and y the void function by reference solved the problem, I am grateful for the useful advice this function working and need RAM 600kb
void add(mpz_t& x, mpz_t& y, mpz_t& X, mpz_t& Y, mpz_t& P) {
mpz_t a, b, c, d, f;
mpz_inits(a, b, c, d, f, 0);
//lambda
mpz_sub(a, Y, y);
mpz_sub(b, X, x);
mpz_invert(c, b, P);
mpz_mul(b, a, c);
mpz_mod(f, b, P);
//point x
mpz_mul(a, f, f);
mpz_sub(b, a, x);
mpz_sub(c, b, X);
mpz_mod(d, c, P);
//point y
mpz_sub(a, x, d);
mpz_mul(b, f, a);
mpz_sub(c, b, y);
mpz_mod(f, c, P);
//set x, y
mpz_set(x, d);
mpz_set(y, f);
mpz_clears(a, b, c, d, f, nullptr);
}
Upvotes: 0