#1629 wrong double representation

OTHER
open
Cesar Strauss
gcc (462)
Bug
none
Unknown
False
2013-02-11
2012-04-12
Gaetano
No

Hi,
I am experiencing problems in a C++ program due to wrong representation on a double variabile.
I'm using: Windows 7 Enterprise 64 bit

gcc -v
C:\Users\Gaetano>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-
sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-lib
stdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)

As IDE, I use Eclipse for C/C++.

Definition:
float TagliMonete[] = {2.0, 1.0, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01 };

From TagliMonete[0]-TagliMonete[2] everything (in memory) is ok.
TagliMonete[3] is represented in memory as 0.2000000003
TagliMonete[4] is represented in memory as 0.1000000001
TagliMonete[5] is represented in memory as 0.05000000007
TagliMonete[6] is represented in memory as 0.01999999996
TagliMonete[7] is represented in memory as 0.00999999978

I've seen these values in Debug mode.

This is a very big problem due to problem on contabilization.

How can I supersede the problem?

Thanks a lot.

Discussion

  • Earnie Boyd
    Earnie Boyd
    2012-04-12

    Please attach a small code working model that represents the problem with steps to recreate the problem using that working model.

     
  • Earnie Boyd
    Earnie Boyd
    2012-04-12

    • assigned_to: nobody --> cstrauss
     
  • Gaetano
    Gaetano
    2012-04-12

    Sample

     
  • Gaetano
    Gaetano
    2012-04-12

    I've created a sample program with the bug.
    After compiling it, you can executing it by "GreedyCambioBanconote 127.41".
    After the launching if you inspect the memory for the array 'TagliMonete', you'll see the numbers I've reported.

    Are there patches for my compiler ?

    Thanks a lot.

    Ciao

     
  • Earnie Boyd
    Earnie Boyd
    2012-10-19

    Gaetano, is this still a problem in 4.7.0? Did you get this resolved?

     
  • Earnie Boyd
    Earnie Boyd
    2013-02-11

    • milestone: --> OTHER
    • type: --> Bug
    • resolution: --> none
    • category: --> Unknown
    • patch_attached: --> False