rounding.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // french.cpp ----------------------------------------------------------//
  2. // Copyright 2010 Howard Hinnant
  3. // Copyright 2011 Vicente J. Botet Escriba
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. // Adapted to Boost from the original Hawards's code
  7. #include <iostream>
  8. //#include <boost/chrono/chrono_io.hpp>
  9. #include <boost/chrono/floor.hpp>
  10. #include <boost/chrono/round.hpp>
  11. #include <boost/chrono/ceil.hpp>
  12. int main()
  13. {
  14. boost::chrono::milliseconds ms(2500);
  15. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  16. std::cout << boost::chrono::floor<boost::chrono::seconds>(ms).count()
  17. << " seconds\n";
  18. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  19. std::cout << boost::chrono::round<boost::chrono::seconds>(ms).count()
  20. << " seconds\n";
  21. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  22. std::cout << boost::chrono::ceil<boost::chrono::seconds>(ms).count()
  23. << " seconds\n";
  24. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  25. ms = boost::chrono::milliseconds(2516);
  26. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  27. typedef boost::chrono::duration<long, boost::ratio<1, 30> > frame_rate;
  28. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  29. std::cout << boost::chrono::floor<frame_rate>(ms).count()
  30. << " [1/30] seconds\n";
  31. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  32. std::cout << boost::chrono::round<frame_rate>(ms).count()
  33. << " [1/30] seconds\n";
  34. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  35. std::cout << boost::chrono::ceil<frame_rate>(ms).count()
  36. << " [1/30] seconds\n";
  37. std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  38. return 0;
  39. }