summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/chrono/example/rounding.cpp
blob: 31fa59568c7307a8a14d471f919af5416efc0d92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//  french.cpp  ----------------------------------------------------------//

//  Copyright 2010 Howard Hinnant
//  Copyright 2011 Vicente J. Botet Escriba
//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

// Adapted to Boost from the original Hawards's code

#include <iostream>
//#include <boost/chrono/chrono_io.hpp>
#include <boost/chrono/floor.hpp>
#include <boost/chrono/round.hpp>
#include <boost/chrono/ceil.hpp>

int main()
{
  boost::chrono::milliseconds ms(2500);
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  std::cout << boost::chrono::floor<boost::chrono::seconds>(ms).count()
      << " seconds\n";
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  std::cout << boost::chrono::round<boost::chrono::seconds>(ms).count()
      << " seconds\n";
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  std::cout << boost::chrono::ceil<boost::chrono::seconds>(ms).count()
      << " seconds\n";
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  ms = boost::chrono::milliseconds(2516);
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  typedef boost::chrono::duration<long, boost::ratio<1, 30> > frame_rate;
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  std::cout << boost::chrono::floor<frame_rate>(ms).count()
      << " [1/30] seconds\n";
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  std::cout << boost::chrono::round<frame_rate>(ms).count()
      << " [1/30] seconds\n";
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
  std::cout << boost::chrono::ceil<frame_rate>(ms).count()
      << " [1/30] seconds\n";
  std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;

  return 0;
}