https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64808

            Bug ID: 64808
           Summary: static_cast double to int on linux 32
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: friend1992friend1992 at yandex dot ru

I have code :
#include <iostream>
void fun(double _v)
{
    std::cout<<"_v="<<_v<<std::endl;
    long long int var=static_cast< long long int >(_v*1000.);
    std::cout<<"var="<<var<<std::endl;
}
int main(int ac, char** av)
{
    fun(33.33);
    return 0;
}
I try to compile this code on Linux x86_64 with GCC 4.8.2 (g++ test.cpp -o
test64), I get result in console:

_v=33.33
var=33330

but when I try to compile this code on Linux i686 with GCC 4.8.2 (g++ test.cpp
-o test32), I get result in console:

_v=33.33
var=33329

But if I replace "long long int var=static_cast< long long int >(_v*1000.);" to
"double t = _v*1000.; long int var=static_cast< long long int >(t);" I get the
result on Linux i686 with GCC 4.4.5:

_v=33.33
var=33330

Reply via email to