GMP库中有零常数吗?
在程序中,我必须检查某个数字是否等于零。一种方法是初始化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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要测试
Z
为零,您可以测试mpz_sgn(z)== 0
或mpz_size(z)== 0
,您don' t需要一个具有值0的MPZ_T。正如您所注意到的,您还可以将z
与mpz_cmp_ui
或mpz_cmp_si
进行比较。没有预定义的常数0。调用
mpz_init
足够便宜(无分配),可以在需要时创建零。To test if
z
is zero, you can testmpz_sgn(z)==0
ormpz_size(z)==0
, you don't need an mpz_t with value 0. As you noticed, you can also comparez
to a native integer withmpz_cmp_ui
ormpz_cmp_si
.There is no predefined constant 0. Calling
mpz_init
is cheap enough (no allocation) to create a zero if you need one.