tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Question on Stack Overflow about weird rounding with


From: KHMan
Subject: Re: [Tinycc-devel] Question on Stack Overflow about weird rounding with tcc
Date: Wed, 28 Aug 2013 10:32:35 +0800
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5

On 8/28/2013 5:06 AM, David Mertens wrote:
Hey everyone -

I found this question from somebody use tcc v0.9.24:

http://stackoverflow.com/questions/18417788/pow-cast-to-integer-unexpected-result

The basic question is, "Why does tcc's compilation output (100,
99) whereas other compilers output (100, 100)?"

|#include  <stdio.h>
#include  <math.h>

int  main(void)
{
     printf("%d,",  (int)  pow(10,  2));
     printf("%d",  (int)  pow(10,  2));
     return  0;
}|

More useful would be the exact double output from pow(), or dump the raw bytes too. I'm guessing it's almost 100. Anything that use native instructions might experience non-exact results because of the way pow() is calculated. Even old library calls might produce that.

Most C libs guarantee exact results where the number do not overflow the available digits of precision by testing and special-casing for integers.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia




reply via email to

[Prev in Thread] Current Thread [Next in Thread]