#include <iostream>
#include <cmath>
#ifdef CPP11
#define ROUND(x) std::round(x)
#else /* CPP11 */
inline double myRound( double x) {
return ( x >= 0.0 ? std:: floor ( x + 0.5 ) : std:: ceil ( x - 0.5 ) ) ;
}
#define ROUND(x) myRound(x)
#endif /* CPP11 */
int main( )
{
std:: cout << "0.3 rounds to " << ROUND( 0.3 ) << std:: endl ;
std:: cout << "With std::round(), it's " << std:: round ( 0.3 ) << std:: endl ;
std:: cout << "-0.3 rounds to " << ROUND( - 0.3 ) << std:: endl ;
std:: cout << "With std::round(), it's " << std:: round ( - 0.3 ) << std:: endl ;
std:: cout << "12.8 rounds to " << ROUND( 12.8 ) << std:: endl ;
std:: cout << "With std::round(), it's " << std:: round ( 12.8 ) << std:: endl ;
std:: cout << "-31.6 rounds to " << ROUND( - 31.6 ) << std:: endl ;
std:: cout << "With std::round(), it's " << std:: round ( - 31.6 ) << std:: endl ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CgojaWZkZWYgQ1BQMTEKICAgICNkZWZpbmUgUk9VTkQoeCkgc3RkOjpyb3VuZCh4KQojZWxzZSAgICAvKiBDUFAxMSAqLwppbmxpbmUgZG91YmxlIG15Um91bmQoZG91YmxlIHgpIHsKICAgIHJldHVybiAoeCA+PSAwLjAgPyBzdGQ6OmZsb29yKHggKyAwLjUpIDogc3RkOjpjZWlsKHggLSAwLjUpKTsKfQoKICAgICNkZWZpbmUgUk9VTkQoeCkgbXlSb3VuZCh4KQojZW5kaWYgICAvKiBDUFAxMSAqLwoKCmludCBtYWluKCkKewogICBzdGQ6OmNvdXQgPDwgIjAuMyByb3VuZHMgdG8gIiA8PCBST1VORCgwLjMpIDw8IHN0ZDo6ZW5kbDsKICAgc3RkOjpjb3V0IDw8ICJXaXRoIHN0ZDo6cm91bmQoKSwgaXQncyAiIDw8IHN0ZDo6cm91bmQoMC4zKSA8PCBzdGQ6OmVuZGw7CiAgIHN0ZDo6Y291dCA8PC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