This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/29597] New: log expression returns different results when casting
- From: "brad_atcheson at yahoo dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Oct 2006 21:58:38 -0000
- Subject: [Bug c++/29597] New: log expression returns different results when casting
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code should return the base2 logarithm of 64 (ie 6)
double d = log(64.0) / log(2.0);
int i = (int)d;
cout << i;
And indeed it does output "6". However, if you attempt to cast it on the same
line, then it returns 5.
int i2 = (int)( log(64.0) / log(2.0) );
int i3 = static_cast<int>( log(64.0) / log(2.0) );
cout << i2 << i3;
This outputs "55" instead of the expected "66". Visual Studio 2003 outputs
"66".
gcc 4.1.0, Suse Linux 10.1.
--
Summary: log expression returns different results when casting
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: brad_atcheson at yahoo dot ca
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29597