pow() 强制转换为整数,意外结果 [英] pow() cast to integer, unexpected result
问题描述
我在 C 编程语言中为 pow()
函数使用整数转换时遇到了一些问题.我使用的编译器是 Windows 平台的 Tiny C Compiler(tcc 版本 0.9.24).执行以下代码时,输出意外结果100, 99
:
I have some problems using an integer cast for the pow()
function in the C programming language. The compiler I'm using is the Tiny C Compiler (tcc version 0.9.24) for the Windows platform. When executing the following code, it outputs the unexpected result 100, 99
:
#include <stdio.h>
#include <math.h>
int main(void)
{
printf("%d, ", (int) pow(10, 2));
printf("%d", (int) pow(10, 2));
return 0;
}
然而,在 this 在线编译器的输出与预期的一样:100, 100代码>.我不知道是什么导致了这种行为.有什么想法吗?我的编程错误,编译器错误?
However, at this online compiler the output is as expected: 100, 100
. I don't know what is causing this behavior. Any thoughts? Programming error from me, compiler bug?
推荐答案
你在 tcc 中发现了一个 bug.感谢那.补丁刚刚提交到存储库.它将包含在下一个版本中,但这可能需要一段时间.您当然可以拉取源代码并自己构建它.补丁在这里
You found a bug in tcc. Thanks for that. The patch has just been commited to the repository. It will be included in the next release, but that might take a while. You can of course pull the source and build it yourself. The patch is here
http://repo.or.cz/w/tinycc.git/commitdiff/73faaea227a53e365dd75f1dba7a5071c7b5e541
这篇关于pow() 强制转换为整数,意外结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!