DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   windows and linux (http://www.daniweb.com/forums/thread41236.html)

gampalu Mar 16th, 2006 12:14 pm
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,

Narue Mar 16th, 2006 1:18 pm
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).

Rashakil Fol Mar 16th, 2006 1:43 pm
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.

gampalu Mar 16th, 2006 1:47 pm
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:

        
double dAUX;
int iOUT;
...
if ( (floor(dAUX) - dAUX) < (ceil(dAUX) - dAUX) )
                        iOUT = floor(dAUX);
else
                        iOUT = ceil(dAUX);

no?

Rashakil Fol Mar 16th, 2006 2:49 pm
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.

gampalu Mar 16th, 2006 2:57 pm
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 ;)


All times are GMT -4. The time now is 11:26 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC