hola comunidad! tengo la siguiente duda sobre c++, entiendo que tal vez no es un problema relacionado directamente con linux, lo unico que tiene relacion es que para compilar ocupo g++
quisiera saber si alguien puede ayudarme con esto, tengo las siguientes lineas: float mm = 0.4; float nn = 2.8; int xx = 3; int c = (mm * xx + nn); cout << "c: " << c << endl; si hacéis la matemática: 0.4 * 3 + 2.8 = 4 sin embargo el programa de arriba me imprime 3 en qué me equivoqué?, que esta pasando?, porqué al truncar 4, da 3? le he comentado a un amigo (que usa ArchLinux) este problema, pero segun él, su compilador (g++ tambien), el ejecutable imprime 4, las especificaciones del sistema de él son: [mario@ArchLinux Desktop]$ uname -a Linux ArchLinux 2.6.37-ARCH #1 SMP PREEMPT Fri Mar 25 15:10:00 CET 2011 x86_64 Pentium(R) Dual-Core CPU T4400 @ 2.20GHz GenuineIntel GNU/Linux [mario@ArchLinux Desktop]$ g++ --version g++ (GCC) 4.5.2 20110127 (prerelease) Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. al parecer el compilador imprime cosas distintas segun el sistema, mi sistema es un Ubuntu 11.04 y la version de g++: joe@joe-laptop:~/Escritorio$ uname -a Linux joe-laptop 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux joe@joe-laptop:~/Escritorio$ g++ --version g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. joe@joe-laptop:~/Escritorio$ man g++ | grep 2011 gcc-4.5.2 2011-04-18 GCC(1) que puedo hacer para que me imprima el resultado correcto?, podeis darme una pista de que hice mal?, gracias! -Joe