windows and linux
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,
gampalu
Junior Poster in Training
78 posts since Mar 2006
Reputation Points: 21
Solved Threads: 0
>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).
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
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.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
>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++?>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:
double dAUX;
int iOUT;
...
if ( (floor(dAUX) - dAUX) < (ceil(dAUX) - dAUX) )
iOUT = floor(dAUX);
else
iOUT = ceil(dAUX);
no?
gampalu
Junior Poster in Training
78 posts since Mar 2006
Reputation Points: 21
Solved Threads: 0
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.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
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) 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 ;)
gampalu
Junior Poster in Training
78 posts since Mar 2006
Reputation Points: 21
Solved Threads: 0