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

Bug#501404: marked as done (g++-4.3: Optimization changes output)



Your message dated Thu, 23 Oct 2008 14:59:16 +0200
with message-id <op.ujhac0ayu2flwt@localhost>
and subject line g++-4.3: Optimization changes output
has caused the Debian Bug report #501404,
regarding g++-4.3: Optimization changes output
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
501404: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=501404
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: g++-4.3
Version: 4.3.2-1
Severity: important



Compile the following code with g++:

===

#include <cmath>
#include <iostream>

struct TimeStruct
{
    int millisecond;
    int second;
};


void fillTimeStruct(double time, TimeStruct& gt)
{

    gt.millisecond = std::fmod(time, 1000.0);

    time /= 1000.0;
    
    // This is a safe cast.
    int remainder = static_cast<int>(std::fmod(time, 86400.0));
   
    gt.second = remainder % 60;
}

int main()
{
	double d = 3.0935415006117e+23;
	TimeStruct gt;
	fillTimeStruct(d, gt);
	std::cout << gt.millisecond << std::endl;
	std::cout << gt.second << std::endl;
}

===

With -O2 the output is:
584
52

With -O0 the output is (correct):
584
0

Other Debian g++ versions (e.g. 4.0 and 4.1) don't have this problem, 
neither do other distros.


-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-486
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages g++-4.3 depends on:
ii  gcc-4.3                   4.3.2-1        The GNU C compiler
ii  gcc-4.3-base              4.3.2-1        The GNU Compiler Collection (base 
ii  libc6                     2.7-13         GNU C Library: Shared libraries
ii  libgmp3c2                 2:4.2.2+dfsg-3 Multiprecision arithmetic library
ii  libmpfr1ldbl              2.3.1.dfsg.1-2 multiple precision floating-point 
ii  libstdc++6-4.3-dev        4.3.2-1        The GNU Standard C++ Library v3 (d

g++-4.3 recommends no packages.

Versions of packages g++-4.3 suggests:
pn  g++-4.3-multilib              <none>     (no description available)
pn  gcc-4.3-doc                   <none>     (no description available)
pn  libstdc++6-4.3-dbg            <none>     (no description available)

-- no debconf information



--- End Message ---
--- Begin Message ---
Hello,

sorry, but this is not a bug. Double precision is insufficient for your calculation, so you get different results depending on whether the intermediate result (time/1000.0) is or isn't truncated to double precision. Both possibilities are allowed by the standard.

Btw, your "d" is exactly

309354150061170002755584

that means time/1000 is exactly

309354150061170002755.5840

and (time/1000) % 86400 is

31555.584

because

3580487847930208*86400+31555 = 309354150061170002755

which means 31555 (or 55 mod 60) is the exact result of the computation.

If your program relies on truncation of intermediate results (to get consistent, not more precise results), try option -ffloat-store.

Regards
    Jiri Palecek

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


--- End Message ---

Reply to: