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;
}
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?
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