ratio_fwd.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // ratio_fwd.hpp ---------------------------------------------------------------//
  2. // Copyright 2008 Howard Hinnant
  3. // Copyright 2008 Beman Dawes
  4. // Copyright 2009 Vicente J. Botet Escriba
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // See http://www.boost.org/LICENSE_1_0.txt
  7. /*
  8. This code was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
  9. Many thanks to Howard for making his code available under the Boost license.
  10. The original code was modified to conform to Boost conventions and to section
  11. 20.4 Compile-time rational arithmetic [ratio], of the C++ committee working
  12. paper N2798.
  13. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
  14. time2_demo contained this comment:
  15. Much thanks to Andrei Alexandrescu,
  16. Walter Brown,
  17. Peter Dimov,
  18. Jeff Garland,
  19. Terry Golubiewski,
  20. Daniel Krugler,
  21. Anthony Williams.
  22. */
  23. // The way overflow is managed for ratio_less is taken from llvm/libcxx/include/ratio
  24. #ifndef BOOST_RATIO_RATIO_FWD_HPP
  25. #define BOOST_RATIO_RATIO_FWD_HPP
  26. #include <boost/ratio/config.hpp>
  27. #if defined(__GNUC__) && (__GNUC__ >= 4)
  28. #pragma GCC system_header
  29. #endif
  30. namespace boost
  31. {
  32. //----------------------------------------------------------------------------//
  33. // //
  34. // 20.6 Compile-time rational arithmetic [ratio] //
  35. // //
  36. //----------------------------------------------------------------------------//
  37. // ratio
  38. template <boost::intmax_t N, boost::intmax_t D = 1> class ratio;
  39. // ratio arithmetic
  40. template <class R1, class R2> struct ratio_add;
  41. template <class R1, class R2> struct ratio_subtract;
  42. template <class R1, class R2> struct ratio_multiply;
  43. template <class R1, class R2> struct ratio_divide;
  44. #ifdef BOOST_RATIO_EXTENSIONS
  45. template <class R1, class R2> struct ratio_gcd;
  46. template <class R1, class R2> struct ratio_lcm;
  47. template <class R> struct ratio_negate;
  48. template <class R> struct ratio_abs;
  49. template <class R> struct ratio_sign;
  50. template <class R, int P> struct ratio_power;
  51. #endif
  52. // ratio comparison
  53. template <class R1, class R2> struct ratio_equal;
  54. template <class R1, class R2> struct ratio_not_equal;
  55. template <class R1, class R2> struct ratio_less;
  56. template <class R1, class R2> struct ratio_less_equal;
  57. template <class R1, class R2> struct ratio_greater;
  58. template <class R1, class R2> struct ratio_greater_equal;
  59. // convenience SI typedefs
  60. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000000000)> atto;
  61. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000000)> femto;
  62. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000)> pico;
  63. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000)> nano;
  64. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000)> micro;
  65. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000)> milli;
  66. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(100)> centi;
  67. typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(10)> deci;
  68. typedef ratio< BOOST_RATIO_INTMAX_C(10), BOOST_RATIO_INTMAX_C(1)> deca;
  69. typedef ratio< BOOST_RATIO_INTMAX_C(100), BOOST_RATIO_INTMAX_C(1)> hecto;
  70. typedef ratio< BOOST_RATIO_INTMAX_C(1000), BOOST_RATIO_INTMAX_C(1)> kilo;
  71. typedef ratio< BOOST_RATIO_INTMAX_C(1000000), BOOST_RATIO_INTMAX_C(1)> mega;
  72. typedef ratio< BOOST_RATIO_INTMAX_C(1000000000), BOOST_RATIO_INTMAX_C(1)> giga;
  73. typedef ratio< BOOST_RATIO_INTMAX_C(1000000000000), BOOST_RATIO_INTMAX_C(1)> tera;
  74. typedef ratio< BOOST_RATIO_INTMAX_C(1000000000000000), BOOST_RATIO_INTMAX_C(1)> peta;
  75. typedef ratio<BOOST_RATIO_INTMAX_C(1000000000000000000), BOOST_RATIO_INTMAX_C(1)> exa;
  76. #ifdef BOOST_RATIO_EXTENSIONS
  77. #define BOOST_RATIO_1024 BOOST_RATIO_INTMAX_C(1024)
  78. // convenience IEC typedefs
  79. typedef ratio< BOOST_RATIO_1024> kibi;
  80. typedef ratio< BOOST_RATIO_1024*BOOST_RATIO_1024> mebi;
  81. typedef ratio< BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024> gibi;
  82. typedef ratio< BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024> tebi;
  83. typedef ratio< BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024> pebi;
  84. typedef ratio<BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024*BOOST_RATIO_1024> exbi;
  85. #endif
  86. } // namespace boost
  87. #endif // BOOST_RATIO_HPP