944,033 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2259
  • C++ RSS
Mar 16th, 2006
0

windows and linux

Expand Post »
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,
Similar Threads
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006
Mar 16th, 2006
0

Re: windows and linux

>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).
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 16th, 2006
2

Re: windows and linux

Quote 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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Mar 16th, 2006
0

Re: windows and linux

Quote 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++?

Quote 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:

C++ Syntax (Toggle Plain Text)
  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?
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006
Mar 16th, 2006
2

Re: windows and linux

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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Mar 16th, 2006
0

Re: windows and linux

Quote 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)

Quote 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
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: hiii all
Next Thread in C++ Forum Timeline: Starting C++ With Knoppix





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC