ratio 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. // ratio -*- C++ -*-
  2. // Copyright (C) 2008-2019 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/ratio
  21. * This is a Standard C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_RATIO
  24. #define _GLIBCXX_RATIO 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. #include <type_traits>
  30. #include <cstdint> // intmax_t, uintmax_t
  31. namespace std _GLIBCXX_VISIBILITY(default)
  32. {
  33. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  34. /**
  35. * @defgroup ratio Rational Arithmetic
  36. * @ingroup utilities
  37. *
  38. * Compile time representation of finite rational numbers.
  39. * @{
  40. */
  41. template<intmax_t _Pn>
  42. struct __static_sign
  43. : integral_constant<intmax_t, (_Pn < 0) ? -1 : 1>
  44. { };
  45. template<intmax_t _Pn>
  46. struct __static_abs
  47. : integral_constant<intmax_t, _Pn * __static_sign<_Pn>::value>
  48. { };
  49. template<intmax_t _Pn, intmax_t _Qn>
  50. struct __static_gcd
  51. : __static_gcd<_Qn, (_Pn % _Qn)>
  52. { };
  53. template<intmax_t _Pn>
  54. struct __static_gcd<_Pn, 0>
  55. : integral_constant<intmax_t, __static_abs<_Pn>::value>
  56. { };
  57. template<intmax_t _Qn>
  58. struct __static_gcd<0, _Qn>
  59. : integral_constant<intmax_t, __static_abs<_Qn>::value>
  60. { };
  61. // Let c = 2^(half # of bits in an intmax_t)
  62. // then we find a1, a0, b1, b0 s.t. N = a1*c + a0, M = b1*c + b0
  63. // The multiplication of N and M becomes,
  64. // N * M = (a1 * b1)c^2 + (a0 * b1 + b0 * a1)c + a0 * b0
  65. // Multiplication is safe if each term and the sum of the terms
  66. // is representable by intmax_t.
  67. template<intmax_t _Pn, intmax_t _Qn>
  68. struct __safe_multiply
  69. {
  70. private:
  71. static const uintmax_t __c = uintmax_t(1) << (sizeof(intmax_t) * 4);
  72. static const uintmax_t __a0 = __static_abs<_Pn>::value % __c;
  73. static const uintmax_t __a1 = __static_abs<_Pn>::value / __c;
  74. static const uintmax_t __b0 = __static_abs<_Qn>::value % __c;
  75. static const uintmax_t __b1 = __static_abs<_Qn>::value / __c;
  76. static_assert(__a1 == 0 || __b1 == 0,
  77. "overflow in multiplication");
  78. static_assert(__a0 * __b1 + __b0 * __a1 < (__c >> 1),
  79. "overflow in multiplication");
  80. static_assert(__b0 * __a0 <= __INTMAX_MAX__,
  81. "overflow in multiplication");
  82. static_assert((__a0 * __b1 + __b0 * __a1) * __c
  83. <= __INTMAX_MAX__ - __b0 * __a0,
  84. "overflow in multiplication");
  85. public:
  86. static const intmax_t value = _Pn * _Qn;
  87. };
  88. // Some double-precision utilities, where numbers are represented as
  89. // __hi*2^(8*sizeof(uintmax_t)) + __lo.
  90. template<uintmax_t __hi1, uintmax_t __lo1, uintmax_t __hi2, uintmax_t __lo2>
  91. struct __big_less
  92. : integral_constant<bool, (__hi1 < __hi2
  93. || (__hi1 == __hi2 && __lo1 < __lo2))>
  94. { };
  95. template<uintmax_t __hi1, uintmax_t __lo1, uintmax_t __hi2, uintmax_t __lo2>
  96. struct __big_add
  97. {
  98. static constexpr uintmax_t __lo = __lo1 + __lo2;
  99. static constexpr uintmax_t __hi = (__hi1 + __hi2 +
  100. (__lo1 + __lo2 < __lo1)); // carry
  101. };
  102. // Subtract a number from a bigger one.
  103. template<uintmax_t __hi1, uintmax_t __lo1, uintmax_t __hi2, uintmax_t __lo2>
  104. struct __big_sub
  105. {
  106. static_assert(!__big_less<__hi1, __lo1, __hi2, __lo2>::value,
  107. "Internal library error");
  108. static constexpr uintmax_t __lo = __lo1 - __lo2;
  109. static constexpr uintmax_t __hi = (__hi1 - __hi2 -
  110. (__lo1 < __lo2)); // carry
  111. };
  112. // Same principle as __safe_multiply.
  113. template<uintmax_t __x, uintmax_t __y>
  114. struct __big_mul
  115. {
  116. private:
  117. static constexpr uintmax_t __c = uintmax_t(1) << (sizeof(intmax_t) * 4);
  118. static constexpr uintmax_t __x0 = __x % __c;
  119. static constexpr uintmax_t __x1 = __x / __c;
  120. static constexpr uintmax_t __y0 = __y % __c;
  121. static constexpr uintmax_t __y1 = __y / __c;
  122. static constexpr uintmax_t __x0y0 = __x0 * __y0;
  123. static constexpr uintmax_t __x0y1 = __x0 * __y1;
  124. static constexpr uintmax_t __x1y0 = __x1 * __y0;
  125. static constexpr uintmax_t __x1y1 = __x1 * __y1;
  126. static constexpr uintmax_t __mix = __x0y1 + __x1y0; // possible carry...
  127. static constexpr uintmax_t __mix_lo = __mix * __c;
  128. static constexpr uintmax_t __mix_hi
  129. = __mix / __c + ((__mix < __x0y1) ? __c : 0); // ... added here
  130. typedef __big_add<__mix_hi, __mix_lo, __x1y1, __x0y0> _Res;
  131. public:
  132. static constexpr uintmax_t __hi = _Res::__hi;
  133. static constexpr uintmax_t __lo = _Res::__lo;
  134. };
  135. // Adapted from __udiv_qrnnd_c in longlong.h
  136. // This version assumes that the high bit of __d is 1.
  137. template<uintmax_t __n1, uintmax_t __n0, uintmax_t __d>
  138. struct __big_div_impl
  139. {
  140. private:
  141. static_assert(__d >= (uintmax_t(1) << (sizeof(intmax_t) * 8 - 1)),
  142. "Internal library error");
  143. static_assert(__n1 < __d, "Internal library error");
  144. static constexpr uintmax_t __c = uintmax_t(1) << (sizeof(intmax_t) * 4);
  145. static constexpr uintmax_t __d1 = __d / __c;
  146. static constexpr uintmax_t __d0 = __d % __c;
  147. static constexpr uintmax_t __q1x = __n1 / __d1;
  148. static constexpr uintmax_t __r1x = __n1 % __d1;
  149. static constexpr uintmax_t __m = __q1x * __d0;
  150. static constexpr uintmax_t __r1y = __r1x * __c + __n0 / __c;
  151. static constexpr uintmax_t __r1z = __r1y + __d;
  152. static constexpr uintmax_t __r1
  153. = ((__r1y < __m) ? ((__r1z >= __d) && (__r1z < __m))
  154. ? (__r1z + __d) : __r1z : __r1y) - __m;
  155. static constexpr uintmax_t __q1
  156. = __q1x - ((__r1y < __m)
  157. ? ((__r1z >= __d) && (__r1z < __m)) ? 2 : 1 : 0);
  158. static constexpr uintmax_t __q0x = __r1 / __d1;
  159. static constexpr uintmax_t __r0x = __r1 % __d1;
  160. static constexpr uintmax_t __n = __q0x * __d0;
  161. static constexpr uintmax_t __r0y = __r0x * __c + __n0 % __c;
  162. static constexpr uintmax_t __r0z = __r0y + __d;
  163. static constexpr uintmax_t __r0
  164. = ((__r0y < __n) ? ((__r0z >= __d) && (__r0z < __n))
  165. ? (__r0z + __d) : __r0z : __r0y) - __n;
  166. static constexpr uintmax_t __q0
  167. = __q0x - ((__r0y < __n) ? ((__r0z >= __d)
  168. && (__r0z < __n)) ? 2 : 1 : 0);
  169. public:
  170. static constexpr uintmax_t __quot = __q1 * __c + __q0;
  171. static constexpr uintmax_t __rem = __r0;
  172. private:
  173. typedef __big_mul<__quot, __d> _Prod;
  174. typedef __big_add<_Prod::__hi, _Prod::__lo, 0, __rem> _Sum;
  175. static_assert(_Sum::__hi == __n1 && _Sum::__lo == __n0,
  176. "Internal library error");
  177. };
  178. template<uintmax_t __n1, uintmax_t __n0, uintmax_t __d>
  179. struct __big_div
  180. {
  181. private:
  182. static_assert(__d != 0, "Internal library error");
  183. static_assert(sizeof (uintmax_t) == sizeof (unsigned long long),
  184. "This library calls __builtin_clzll on uintmax_t, which "
  185. "is unsafe on your platform. Please complain to "
  186. "http://gcc.gnu.org/bugzilla/");
  187. static constexpr int __shift = __builtin_clzll(__d);
  188. static constexpr int __coshift_ = sizeof(uintmax_t) * 8 - __shift;
  189. static constexpr int __coshift = (__shift != 0) ? __coshift_ : 0;
  190. static constexpr uintmax_t __c1 = uintmax_t(1) << __shift;
  191. static constexpr uintmax_t __c2 = uintmax_t(1) << __coshift;
  192. static constexpr uintmax_t __new_d = __d * __c1;
  193. static constexpr uintmax_t __new_n0 = __n0 * __c1;
  194. static constexpr uintmax_t __n1_shifted = (__n1 % __d) * __c1;
  195. static constexpr uintmax_t __n0_top = (__shift != 0) ? (__n0 / __c2) : 0;
  196. static constexpr uintmax_t __new_n1 = __n1_shifted + __n0_top;
  197. typedef __big_div_impl<__new_n1, __new_n0, __new_d> _Res;
  198. public:
  199. static constexpr uintmax_t __quot_hi = __n1 / __d;
  200. static constexpr uintmax_t __quot_lo = _Res::__quot;
  201. static constexpr uintmax_t __rem = _Res::__rem / __c1;
  202. private:
  203. typedef __big_mul<__quot_lo, __d> _P0;
  204. typedef __big_mul<__quot_hi, __d> _P1;
  205. typedef __big_add<_P0::__hi, _P0::__lo, _P1::__lo, __rem> _Sum;
  206. // No overflow.
  207. static_assert(_P1::__hi == 0, "Internal library error");
  208. static_assert(_Sum::__hi >= _P0::__hi, "Internal library error");
  209. // Matches the input data.
  210. static_assert(_Sum::__hi == __n1 && _Sum::__lo == __n0,
  211. "Internal library error");
  212. static_assert(__rem < __d, "Internal library error");
  213. };
  214. /**
  215. * @brief Provides compile-time rational arithmetic.
  216. *
  217. * This class template represents any finite rational number with a
  218. * numerator and denominator representable by compile-time constants of
  219. * type intmax_t. The ratio is simplified when instantiated.
  220. *
  221. * For example:
  222. * @code
  223. * std::ratio<7,-21>::num == -1;
  224. * std::ratio<7,-21>::den == 3;
  225. * @endcode
  226. *
  227. */
  228. template<intmax_t _Num, intmax_t _Den = 1>
  229. struct ratio
  230. {
  231. static_assert(_Den != 0, "denominator cannot be zero");
  232. static_assert(_Num >= -__INTMAX_MAX__ && _Den >= -__INTMAX_MAX__,
  233. "out of range");
  234. // Note: sign(N) * abs(N) == N
  235. static constexpr intmax_t num =
  236. _Num * __static_sign<_Den>::value / __static_gcd<_Num, _Den>::value;
  237. static constexpr intmax_t den =
  238. __static_abs<_Den>::value / __static_gcd<_Num, _Den>::value;
  239. typedef ratio<num, den> type;
  240. };
  241. template<intmax_t _Num, intmax_t _Den>
  242. constexpr intmax_t ratio<_Num, _Den>::num;
  243. template<intmax_t _Num, intmax_t _Den>
  244. constexpr intmax_t ratio<_Num, _Den>::den;
  245. template<typename _R1, typename _R2>
  246. struct __ratio_multiply
  247. {
  248. private:
  249. static const intmax_t __gcd1 =
  250. __static_gcd<_R1::num, _R2::den>::value;
  251. static const intmax_t __gcd2 =
  252. __static_gcd<_R2::num, _R1::den>::value;
  253. public:
  254. typedef ratio<
  255. __safe_multiply<(_R1::num / __gcd1),
  256. (_R2::num / __gcd2)>::value,
  257. __safe_multiply<(_R1::den / __gcd2),
  258. (_R2::den / __gcd1)>::value> type;
  259. static constexpr intmax_t num = type::num;
  260. static constexpr intmax_t den = type::den;
  261. };
  262. template<typename _R1, typename _R2>
  263. constexpr intmax_t __ratio_multiply<_R1, _R2>::num;
  264. template<typename _R1, typename _R2>
  265. constexpr intmax_t __ratio_multiply<_R1, _R2>::den;
  266. /// ratio_multiply
  267. template<typename _R1, typename _R2>
  268. using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type;
  269. template<typename _R1, typename _R2>
  270. struct __ratio_divide
  271. {
  272. static_assert(_R2::num != 0, "division by 0");
  273. typedef typename __ratio_multiply<
  274. _R1,
  275. ratio<_R2::den, _R2::num>>::type type;
  276. static constexpr intmax_t num = type::num;
  277. static constexpr intmax_t den = type::den;
  278. };
  279. template<typename _R1, typename _R2>
  280. constexpr intmax_t __ratio_divide<_R1, _R2>::num;
  281. template<typename _R1, typename _R2>
  282. constexpr intmax_t __ratio_divide<_R1, _R2>::den;
  283. /// ratio_divide
  284. template<typename _R1, typename _R2>
  285. using ratio_divide = typename __ratio_divide<_R1, _R2>::type;
  286. /// ratio_equal
  287. template<typename _R1, typename _R2>
  288. struct ratio_equal
  289. : integral_constant<bool, _R1::num == _R2::num && _R1::den == _R2::den>
  290. { };
  291. /// ratio_not_equal
  292. template<typename _R1, typename _R2>
  293. struct ratio_not_equal
  294. : integral_constant<bool, !ratio_equal<_R1, _R2>::value>
  295. { };
  296. // Both numbers are positive.
  297. template<typename _R1, typename _R2,
  298. typename _Left = __big_mul<_R1::num,_R2::den>,
  299. typename _Right = __big_mul<_R2::num,_R1::den> >
  300. struct __ratio_less_impl_1
  301. : integral_constant<bool, __big_less<_Left::__hi, _Left::__lo,
  302. _Right::__hi, _Right::__lo>::value>
  303. { };
  304. template<typename _R1, typename _R2,
  305. bool = (_R1::num == 0 || _R2::num == 0
  306. || (__static_sign<_R1::num>::value
  307. != __static_sign<_R2::num>::value)),
  308. bool = (__static_sign<_R1::num>::value == -1
  309. && __static_sign<_R2::num>::value == -1)>
  310. struct __ratio_less_impl
  311. : __ratio_less_impl_1<_R1, _R2>::type
  312. { };
  313. template<typename _R1, typename _R2>
  314. struct __ratio_less_impl<_R1, _R2, true, false>
  315. : integral_constant<bool, _R1::num < _R2::num>
  316. { };
  317. template<typename _R1, typename _R2>
  318. struct __ratio_less_impl<_R1, _R2, false, true>
  319. : __ratio_less_impl_1<ratio<-_R2::num, _R2::den>,
  320. ratio<-_R1::num, _R1::den> >::type
  321. { };
  322. /// ratio_less
  323. template<typename _R1, typename _R2>
  324. struct ratio_less
  325. : __ratio_less_impl<_R1, _R2>::type
  326. { };
  327. /// ratio_less_equal
  328. template<typename _R1, typename _R2>
  329. struct ratio_less_equal
  330. : integral_constant<bool, !ratio_less<_R2, _R1>::value>
  331. { };
  332. /// ratio_greater
  333. template<typename _R1, typename _R2>
  334. struct ratio_greater
  335. : integral_constant<bool, ratio_less<_R2, _R1>::value>
  336. { };
  337. /// ratio_greater_equal
  338. template<typename _R1, typename _R2>
  339. struct ratio_greater_equal
  340. : integral_constant<bool, !ratio_less<_R1, _R2>::value>
  341. { };
  342. #if __cplusplus > 201402L
  343. template <typename _R1, typename _R2>
  344. inline constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value;
  345. template <typename _R1, typename _R2>
  346. inline constexpr bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value;
  347. template <typename _R1, typename _R2>
  348. inline constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value;
  349. template <typename _R1, typename _R2>
  350. inline constexpr bool ratio_less_equal_v =
  351. ratio_less_equal<_R1, _R2>::value;
  352. template <typename _R1, typename _R2>
  353. inline constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value;
  354. template <typename _R1, typename _R2>
  355. inline constexpr bool ratio_greater_equal_v
  356. = ratio_greater_equal<_R1, _R2>::value;
  357. #endif // C++17
  358. template<typename _R1, typename _R2,
  359. bool = (_R1::num >= 0),
  360. bool = (_R2::num >= 0),
  361. bool = ratio_less<ratio<__static_abs<_R1::num>::value, _R1::den>,
  362. ratio<__static_abs<_R2::num>::value, _R2::den> >::value>
  363. struct __ratio_add_impl
  364. {
  365. private:
  366. typedef typename __ratio_add_impl<
  367. ratio<-_R1::num, _R1::den>,
  368. ratio<-_R2::num, _R2::den> >::type __t;
  369. public:
  370. typedef ratio<-__t::num, __t::den> type;
  371. };
  372. // True addition of nonnegative numbers.
  373. template<typename _R1, typename _R2, bool __b>
  374. struct __ratio_add_impl<_R1, _R2, true, true, __b>
  375. {
  376. private:
  377. static constexpr uintmax_t __g = __static_gcd<_R1::den, _R2::den>::value;
  378. static constexpr uintmax_t __d2 = _R2::den / __g;
  379. typedef __big_mul<_R1::den, __d2> __d;
  380. typedef __big_mul<_R1::num, _R2::den / __g> __x;
  381. typedef __big_mul<_R2::num, _R1::den / __g> __y;
  382. typedef __big_add<__x::__hi, __x::__lo, __y::__hi, __y::__lo> __n;
  383. static_assert(__n::__hi >= __x::__hi, "Internal library error");
  384. typedef __big_div<__n::__hi, __n::__lo, __g> __ng;
  385. static constexpr uintmax_t __g2 = __static_gcd<__ng::__rem, __g>::value;
  386. typedef __big_div<__n::__hi, __n::__lo, __g2> __n_final;
  387. static_assert(__n_final::__rem == 0, "Internal library error");
  388. static_assert(__n_final::__quot_hi == 0 &&
  389. __n_final::__quot_lo <= __INTMAX_MAX__, "overflow in addition");
  390. typedef __big_mul<_R1::den / __g2, __d2> __d_final;
  391. static_assert(__d_final::__hi == 0 &&
  392. __d_final::__lo <= __INTMAX_MAX__, "overflow in addition");
  393. public:
  394. typedef ratio<__n_final::__quot_lo, __d_final::__lo> type;
  395. };
  396. template<typename _R1, typename _R2>
  397. struct __ratio_add_impl<_R1, _R2, false, true, true>
  398. : __ratio_add_impl<_R2, _R1>
  399. { };
  400. // True subtraction of nonnegative numbers yielding a nonnegative result.
  401. template<typename _R1, typename _R2>
  402. struct __ratio_add_impl<_R1, _R2, true, false, false>
  403. {
  404. private:
  405. static constexpr uintmax_t __g = __static_gcd<_R1::den, _R2::den>::value;
  406. static constexpr uintmax_t __d2 = _R2::den / __g;
  407. typedef __big_mul<_R1::den, __d2> __d;
  408. typedef __big_mul<_R1::num, _R2::den / __g> __x;
  409. typedef __big_mul<-_R2::num, _R1::den / __g> __y;
  410. typedef __big_sub<__x::__hi, __x::__lo, __y::__hi, __y::__lo> __n;
  411. typedef __big_div<__n::__hi, __n::__lo, __g> __ng;
  412. static constexpr uintmax_t __g2 = __static_gcd<__ng::__rem, __g>::value;
  413. typedef __big_div<__n::__hi, __n::__lo, __g2> __n_final;
  414. static_assert(__n_final::__rem == 0, "Internal library error");
  415. static_assert(__n_final::__quot_hi == 0 &&
  416. __n_final::__quot_lo <= __INTMAX_MAX__, "overflow in addition");
  417. typedef __big_mul<_R1::den / __g2, __d2> __d_final;
  418. static_assert(__d_final::__hi == 0 &&
  419. __d_final::__lo <= __INTMAX_MAX__, "overflow in addition");
  420. public:
  421. typedef ratio<__n_final::__quot_lo, __d_final::__lo> type;
  422. };
  423. template<typename _R1, typename _R2>
  424. struct __ratio_add
  425. {
  426. typedef typename __ratio_add_impl<_R1, _R2>::type type;
  427. static constexpr intmax_t num = type::num;
  428. static constexpr intmax_t den = type::den;
  429. };
  430. template<typename _R1, typename _R2>
  431. constexpr intmax_t __ratio_add<_R1, _R2>::num;
  432. template<typename _R1, typename _R2>
  433. constexpr intmax_t __ratio_add<_R1, _R2>::den;
  434. /// ratio_add
  435. template<typename _R1, typename _R2>
  436. using ratio_add = typename __ratio_add<_R1, _R2>::type;
  437. template<typename _R1, typename _R2>
  438. struct __ratio_subtract
  439. {
  440. typedef typename __ratio_add<
  441. _R1,
  442. ratio<-_R2::num, _R2::den>>::type type;
  443. static constexpr intmax_t num = type::num;
  444. static constexpr intmax_t den = type::den;
  445. };
  446. template<typename _R1, typename _R2>
  447. constexpr intmax_t __ratio_subtract<_R1, _R2>::num;
  448. template<typename _R1, typename _R2>
  449. constexpr intmax_t __ratio_subtract<_R1, _R2>::den;
  450. /// ratio_subtract
  451. template<typename _R1, typename _R2>
  452. using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type;
  453. typedef ratio<1, 1000000000000000000> atto;
  454. typedef ratio<1, 1000000000000000> femto;
  455. typedef ratio<1, 1000000000000> pico;
  456. typedef ratio<1, 1000000000> nano;
  457. typedef ratio<1, 1000000> micro;
  458. typedef ratio<1, 1000> milli;
  459. typedef ratio<1, 100> centi;
  460. typedef ratio<1, 10> deci;
  461. typedef ratio< 10, 1> deca;
  462. typedef ratio< 100, 1> hecto;
  463. typedef ratio< 1000, 1> kilo;
  464. typedef ratio< 1000000, 1> mega;
  465. typedef ratio< 1000000000, 1> giga;
  466. typedef ratio< 1000000000000, 1> tera;
  467. typedef ratio< 1000000000000000, 1> peta;
  468. typedef ratio< 1000000000000000000, 1> exa;
  469. // @} group ratio
  470. _GLIBCXX_END_NAMESPACE_VERSION
  471. } // namespace
  472. #endif // C++11
  473. #endif //_GLIBCXX_RATIO