 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
edward.birch@gmail.com Guest
|
Posted: Sat Jun 17, 2006 9:10 am Post subject: floating point |
|
|
The follwoing program produces "6" when compiled/run under MSDEV
2005/Windows and
"6" when compiled/run under g++/Linux.
Anyone have any ideas on how to make MSDEV behave the same as Linux.
--
#include <stdio.h>
int main(int argc, char * argv[])
{
double v = 0.6;
printf("%d\n", int(v * 10.0));
return 0;
}
MSDEV 2005/Windows ==> 6
MSDEV 2003/Windows ==> 6
g++/Linux ==> 5 |
|
| Back to top |
|
 |
Peter Jansson Guest
|
Posted: Sat Jun 17, 2006 9:10 am Post subject: Re: floating point |
|
|
edward.birch (AT) gmail (DOT) com wrote:
| Quote: | The follwoing program produces "6" when compiled/run under MSDEV
2005/Windows and
"6" when compiled/run under g++/Linux.
Anyone have any ideas on how to make MSDEV behave the same as Linux.
--
#include <stdio.h
int main(int argc, char * argv[])
{
double v = 0.6;
printf("%d\n", int(v * 10.0));
return 0;
}
MSDEV 2005/Windows ==> 6
MSDEV 2003/Windows ==> 6
g++/Linux ==> 5
|
Why convert the (v*10.0) expression to an int by truncating? I suggest
you consider to printf a double value instead of an int. Or perhaps v
should an int (6) and you could printf (v*1)=v instead?
Sincerely,
Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/ |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|