GMP库中有零常数吗?

发布于 2025-01-31 01:48:09 字数 451 浏览 1 评论 0原文

在程序中,我必须检查某个数字是否等于零。一种方法是初始化mpz_t并检查原始数字是否等于它。但是当然,GMP中的常数为零,例如biginteger.zero在Java&科特林?

(不知何故 this 页面不包含我想要的;我做了“检查”精美的手册“使用搜索引擎,适合那些遵守此页面标准礼貌水平的人。)

非常感谢您!

编辑:我刚刚了解到,一个人可以将MPZ_T与整数进行比较,以便可以做mpz_cmp_ui(varible,0)== 0之类的事情。马克·格里斯(Marc Glisse)的答案提供的解决方案甚至更快。

In a program, I have to check whether a certain number is equal to zero. One way to do it is to just initialise an mpz_t and check whether the original number equals it. But surely there is a zero constant in GMP, like BigInteger.ZERO in Java & Kotlin?

(Somehow this page doesn't contain what I want; I did "check the fine manual" & use a search engine, for those of you who adhere to the standard level of politeness on this page.)

Thank you very much in advance!

EDIT: I just learned that one may compare an mpz_t to an integer, so that one may do something like mpz_cmp_ui(variable, 0) == 0. The solutions given by the answer by Marc Glisse are probably even faster.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最偏执的依靠 2025-02-07 01:48:09

要测试Z为零,您可以测试mpz_sgn(z)== 0mpz_size(z)== 0,您don' t需要一个具有值0的MPZ_T。正如您所注意到的,您还可以将zmpz_cmp_uimpz_cmp_si进行比较。

没有预定义的常数0。调用mpz_init足够便宜(无分配),可以在需要时创建零。

To test if z is zero, you can test mpz_sgn(z)==0 or mpz_size(z)==0, you don't need an mpz_t with value 0. As you noticed, you can also compare z to a native integer with mpz_cmp_ui or mpz_cmp_si.

There is no predefined constant 0. Calling mpz_init is cheap enough (no allocation) to create a zero if you need one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文