c++ - 使用 GMP 获取函数
问题描述
我有点(x,y),我想添加另一个点。我只写公式,但我想获得函数:
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);
}
在我看来,这应该不难,但我一整天都在开车。点 gp = {x, y}; 错误:数组必须用大括号括起来的初始化程序初始化
我只想有一个点 (x, y) 来获得输出的下一个点。它不一定是一个结构,我尝试了对和元组,它仍然没有帮助。
解决方案
真的,如果我只需要更改 x 和 y 的值 void 函数通过引用解决了问题,为什么还要麻烦,我感谢有用的建议这个函数工作并且需要 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);
}
推荐阅读
- android - 在 Android Studio 中切换 Activity 时总是报错
- c# - 这些 foreach 循环可以合并为一个吗?
- assembly - 将 AH 存储到 DW 变量中时“操作数类型不匹配”
- nginx - 如何将 auth_request 发送到 nginx 中的变量 URI?
- asp.net - 将 asp.net 核心应用程序发布到 azure 时出错
- php - 如何使用孩子创建 json 数组 php
- cloud - activiti-7 setup *** 没有规则来制作目标 `activiti-cloud-audit'
- angular - Angular 可观察到的错误不会使用 ChangeDetectionStrategy.OnPush 刷新界面
- python - 如何将 utf-8 编码转换为字符串?
- regex - 使用正则表达式选择数据并清理它以输出