简体   繁体   English

这是GMP 4.1.2中的错误,还是我做错了什么?

[英]Is this a bug in GMP 4.1.2 or is it something I'm doing wrong?

To this bit of code I pass the string "kellogs special k" and I get 1 which means that the string is an integer. 在这部分代码中,我传递了字符串"kellogs special k" ,得到1 ,这表示该字符串是整数。 What on earth am I doing wrong? 我到底在做什么错? Or is it a GMP problem? 还是GMP问题?

#define F(x) mpf_t (x); mpf_init( (x) );

long __stdcall FBIGISINTEGER(BSTR p1) {
    USES_CONVERSION;
    F(n1);
    LPSTR sNum1 = W2A( p1 );
    mpf_set_str( n1, sNum1, 10 );
    return mpf_integer_p( n1 );
}

By the way, if anyone's going to suggest using a more recent GMP, please can you give me the web address of the static LIB for Windows. 顺便说一句,如果有人建议使用更新的GMP,请给我Windows静态LIB的网址。 TIA. TIA。

You should check the return value of mpf_set_str . 您应该检查mpf_set_str的返回值。 It returns 0 on success and -1 on failure. 成功返回0 ,失败返回-1 In this case it would have returned a failure and n1 is left untouched. 在这种情况下,它会返回一个故障,并且n1保持不变。 mpf_init initialized it to zero, so testing whether zero is an integer with mpf_integer_p returns true. mpf_init将其初始化为零,因此使用mpf_integer_p测试零是否为整数是mpf_integer_p返回true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM