windows and linux

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training

windows and linux

 
0
  #1
Mar 16th, 2006
Hi all!

I'm working in a project in visual c++ 6.0 with the console application and I want to ask you how to create a program that has portability to work in both platforms, windows and linux.

Another thing, which function we use to round a double to the nearest int number?

Thanks,
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,574
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: windows and linux

 
0
  #2
Mar 16th, 2006
>how to create a program that has portability to work in both platforms, windows and linux.
Write 100% standard C++, or conditionally compile two different programs customized for the two operating systems.

>which function we use to round a double to the nearest int number?
You'll need to write it yourself, or use a clever workaround. Alternatively, if all you need is to print the rounded double, any formatted output option will do it for you (which opens up ideas for those clever workarounds I was talking about).
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: windows and linux

 
0
  #3
Mar 16th, 2006
Originally Posted by Narue
Alternatively, if all you need is to print the rounded double, any formatted output option will do it for you (which opens up ideas for those clever workarounds I was talking about).
Eww! That would just be sick.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training

Re: windows and linux

 
0
  #4
Mar 16th, 2006
Originally Posted by Narue
>Write 100% standard C++, or conditionally compile two different programs customized for the two operating systems.
How do I know what is 100% standard C++?

Originally Posted by Narue
>You'll need to write it yourself, or use a clever workaround. Alternatively, if all you need is to print the rounded double, any formatted output option will do it for you (which opens up ideas for those clever workarounds I was talking about).
Maybe using a workaround like this:

  1.  
  2. double dAUX;
  3. int iOUT;
  4. ...
  5. if ( (floor(dAUX) - dAUX) < (ceil(dAUX) - dAUX) )
  6. iOUT = floor(dAUX);
  7. else
  8. iOUT = ceil(dAUX);

no?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: windows and linux

 
0
  #5
Mar 16th, 2006
Not bad, but where you say (floor(dAUX) - dAUX) < (ceil(dAUX) - dAUX), I think you mean (dAUX - floor(dAUX)) < (ceil(dAUX) - dAUX).

Personally, I prefer floor(dAUX + 0.5), if I want to always round .5s in the positive direction.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training

Re: windows and linux

 
0
  #6
Mar 16th, 2006
Originally Posted by Rashakil Fol
Not bad, but where you say (floor(dAUX) - dAUX) < (ceil(dAUX) - dAUX), I think you mean (dAUX - floor(dAUX)) < (ceil(dAUX) - dAUX).
I meant like I had but with this:
fabs(floor(dAUX) - dAUX)) < fabs(ceil(dAUX) - dAUX)

Originally Posted by Rashakil Fol
Personally, I prefer floor(dAUX + 0.5), if I want to always round .5s in the positive direction.
Your suggestion is much more simple than mine, I like it, thanks Rashaki Fol and Narue
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC