C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

floating point

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
edward.birch@gmail.com
Guest





PostPosted: Sat Jun 17, 2006 9:10 am    Post subject: floating point Reply with 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
Back to top
Peter Jansson
Guest





PostPosted: Sat Jun 17, 2006 9:10 am    Post subject: Re: floating point Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.