public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24014] New: casting int to double with got wrong result
@ 2005-09-22 15:44 gcc-bugzilla at gcc dot gnu dot org
  2005-09-22 15:48 ` [Bug c++/24014] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2005-09-22 15:44 UTC (permalink / raw)
  To: gcc-bugs


	I've written an macro for log2 calculation to calculate the exponent of one value.
	Than I cast this value to from double to int.
	The 2 values double and int differs. 
	example:
	log2(8) should be 3 but after casting to int its 2.
	This bug could be reproduced on 2 different linux distributions (Debian GNU/Linux and Fedora Core 2) with different compiler versions.

Environment:
System: Linux lux 2.6.9 #2 Tue Dec 28 22:27:56 CET 2004 i686 GNU/Linux
Architecture: i686

	
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --enable-__cxa_atexit --with-system-zlib --enable-nls --without-included-gettext --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux

How-To-Repeat:
	use this code to reproduce it
	--- code ---
	#include <math.h>
	#include <stdlib.h>
	#define log2(val) (log((val))/log(2.0))
	int main()
	{       
	      int n1=log2(8);
		double d1=log2(8);
		printf("%d %f\n",n1,d1);
		return 0;
	 }
	--- end ---
------- Additional Comments From u dot strempel at gmx dot de  2005-09-22 15:44 -------
Fix:
	For workaround I implemented a function for log2.

-- 
           Summary: casting int to double with got wrong result
           Product: gcc
           Version: 3.3.5
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: u dot strempel at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24014


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/24014] casting int to double with got wrong result
  2005-09-22 15:44 [Bug c++/24014] New: casting int to double with got wrong result gcc-bugzilla at gcc dot gnu dot org
@ 2005-09-22 15:48 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-22 15:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-22 15:48 -------
This is really not a bug.

This is a dup of 323.

*** This bug has been marked as a duplicate of 323 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24014


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-22 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-22 15:44 [Bug c++/24014] New: casting int to double with got wrong result gcc-bugzilla at gcc dot gnu dot org
2005-09-22 15:48 ` [Bug c++/24014] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).