blob: f623a062f2ce5df99bc528df610a34a44b299839 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- ratio -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_RATIO
12#define _LIBCPP_RATIO
13
14/*
15 ratio synopsis
16
17namespace std
18{
19
20template <intmax_t N, intmax_t D = 1>
21class ratio
22{
23public:
Marshall Clowe9d03062015-04-16 21:36:54 +000024 static constexpr intmax_t num;
25 static constexpr intmax_t den;
Howard Hinnantd397d032010-11-24 17:05:06 +000026 typedef ratio<num, den> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027};
28
29// ratio arithmetic
Howard Hinnantd397d032010-11-24 17:05:06 +000030template <class R1, class R2> using ratio_add = ...;
31template <class R1, class R2> using ratio_subtract = ...;
32template <class R1, class R2> using ratio_multiply = ...;
33template <class R1, class R2> using ratio_divide = ...;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034
35// ratio comparison
36template <class R1, class R2> struct ratio_equal;
37template <class R1, class R2> struct ratio_not_equal;
38template <class R1, class R2> struct ratio_less;
39template <class R1, class R2> struct ratio_less_equal;
40template <class R1, class R2> struct ratio_greater;
41template <class R1, class R2> struct ratio_greater_equal;
42
43// convenience SI typedefs
44typedef ratio<1, 1000000000000000000000000> yocto; // not supported
45typedef ratio<1, 1000000000000000000000> zepto; // not supported
46typedef ratio<1, 1000000000000000000> atto;
47typedef ratio<1, 1000000000000000> femto;
48typedef ratio<1, 1000000000000> pico;
49typedef ratio<1, 1000000000> nano;
50typedef ratio<1, 1000000> micro;
51typedef ratio<1, 1000> milli;
52typedef ratio<1, 100> centi;
53typedef ratio<1, 10> deci;
54typedef ratio< 10, 1> deca;
55typedef ratio< 100, 1> hecto;
56typedef ratio< 1000, 1> kilo;
57typedef ratio< 1000000, 1> mega;
58typedef ratio< 1000000000, 1> giga;
59typedef ratio< 1000000000000, 1> tera;
60typedef ratio< 1000000000000000, 1> peta;
61typedef ratio< 1000000000000000000, 1> exa;
62typedef ratio< 1000000000000000000000, 1> zetta; // not supported
63typedef ratio<1000000000000000000000000, 1> yotta; // not supported
64
65}
66*/
67
68#include <__config>
69#include <cstdint>
70#include <climits>
71#include <type_traits>
72
Howard Hinnant66c6f972011-11-29 16:45:27 +000073#include <__undef_min_max>
74
Howard Hinnant08e17472011-10-17 20:05:10 +000075#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000076#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000077#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078
79_LIBCPP_BEGIN_NAMESPACE_STD
80
81// __static_gcd
82
83template <intmax_t _Xp, intmax_t _Yp>
84struct __static_gcd
85{
86 static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value;
87};
88
89template <intmax_t _Xp>
90struct __static_gcd<_Xp, 0>
91{
92 static const intmax_t value = _Xp;
93};
94
Howard Hinnantce6884c2011-11-01 23:13:37 +000095template <>
96struct __static_gcd<0, 0>
97{
98 static const intmax_t value = 1;
99};
100
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101// __static_lcm
102
103template <intmax_t _Xp, intmax_t _Yp>
104struct __static_lcm
105{
106 static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp;
107};
108
109template <intmax_t _Xp>
110struct __static_abs
111{
112 static const intmax_t value = _Xp < 0 ? -_Xp : _Xp;
113};
114
115template <intmax_t _Xp>
116struct __static_sign
117{
118 static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1);
119};
120
121template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
122class __ll_add;
123
124template <intmax_t _Xp, intmax_t _Yp>
125class __ll_add<_Xp, _Yp, 1>
126{
127 static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
128 static const intmax_t max = -min;
129
130 static_assert(_Xp <= max - _Yp, "overflow in __ll_add");
131public:
132 static const intmax_t value = _Xp + _Yp;
133};
134
135template <intmax_t _Xp, intmax_t _Yp>
136class __ll_add<_Xp, _Yp, 0>
137{
138public:
139 static const intmax_t value = _Xp;
140};
141
142template <intmax_t _Xp, intmax_t _Yp>
143class __ll_add<_Xp, _Yp, -1>
144{
145 static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
146 static const intmax_t max = -min;
147
148 static_assert(min - _Yp <= _Xp, "overflow in __ll_add");
149public:
150 static const intmax_t value = _Xp + _Yp;
151};
152
153template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
154class __ll_sub;
155
156template <intmax_t _Xp, intmax_t _Yp>
157class __ll_sub<_Xp, _Yp, 1>
158{
159 static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
160 static const intmax_t max = -min;
161
162 static_assert(min + _Yp <= _Xp, "overflow in __ll_sub");
163public:
164 static const intmax_t value = _Xp - _Yp;
165};
166
167template <intmax_t _Xp, intmax_t _Yp>
168class __ll_sub<_Xp, _Yp, 0>
169{
170public:
171 static const intmax_t value = _Xp;
172};
173
174template <intmax_t _Xp, intmax_t _Yp>
175class __ll_sub<_Xp, _Yp, -1>
176{
177 static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
178 static const intmax_t max = -min;
179
180 static_assert(_Xp <= max + _Yp, "overflow in __ll_sub");
181public:
182 static const intmax_t value = _Xp - _Yp;
183};
184
185template <intmax_t _Xp, intmax_t _Yp>
186class __ll_mul
187{
188 static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
189 static const intmax_t min = nan + 1;
190 static const intmax_t max = -min;
191 static const intmax_t __a_x = __static_abs<_Xp>::value;
192 static const intmax_t __a_y = __static_abs<_Yp>::value;
193
194 static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul");
195public:
196 static const intmax_t value = _Xp * _Yp;
197};
198
199template <intmax_t _Yp>
200class __ll_mul<0, _Yp>
201{
202public:
203 static const intmax_t value = 0;
204};
205
206template <intmax_t _Xp>
207class __ll_mul<_Xp, 0>
208{
209public:
210 static const intmax_t value = 0;
211};
212
213template <>
214class __ll_mul<0, 0>
215{
216public:
217 static const intmax_t value = 0;
218};
219
220// Not actually used but left here in case needed in future maintenance
221template <intmax_t _Xp, intmax_t _Yp>
222class __ll_div
223{
224 static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
225 static const intmax_t min = nan + 1;
226 static const intmax_t max = -min;
227
228 static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div");
229public:
230 static const intmax_t value = _Xp / _Yp;
231};
232
233template <intmax_t _Num, intmax_t _Den = 1>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000234class _LIBCPP_TYPE_VIS_ONLY ratio
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235{
236 static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range");
237 static_assert(_Den != 0, "ratio divide by 0");
238 static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range");
Marshall Clowe9d03062015-04-16 21:36:54 +0000239 static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>::value;
240 static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>::value;
241 static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value;
242 static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>::value;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243public:
Marshall Clowe9d03062015-04-16 21:36:54 +0000244 static _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd;
245 static _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
247 typedef ratio<num, den> type;
248};
249
Eric Fiselierbae11ad2015-05-20 03:15:01 +0000250template <intmax_t _Num, intmax_t _Den>
251_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::num;
252
253template <intmax_t _Num, intmax_t _Den>
254_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::den;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
Howard Hinnantd8bc09b2010-05-18 17:32:30 +0000256template <class _Tp> struct __is_ratio : false_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000257template <intmax_t _Num, intmax_t _Den> struct __is_ratio<ratio<_Num, _Den> > : true_type {};
258
259typedef ratio<1LL, 1000000000000000000LL> atto;
260typedef ratio<1LL, 1000000000000000LL> femto;
261typedef ratio<1LL, 1000000000000LL> pico;
262typedef ratio<1LL, 1000000000LL> nano;
263typedef ratio<1LL, 1000000LL> micro;
264typedef ratio<1LL, 1000LL> milli;
265typedef ratio<1LL, 100LL> centi;
266typedef ratio<1LL, 10LL> deci;
267typedef ratio< 10LL, 1LL> deca;
268typedef ratio< 100LL, 1LL> hecto;
269typedef ratio< 1000LL, 1LL> kilo;
270typedef ratio< 1000000LL, 1LL> mega;
271typedef ratio< 1000000000LL, 1LL> giga;
272typedef ratio< 1000000000000LL, 1LL> tera;
273typedef ratio< 1000000000000000LL, 1LL> peta;
274typedef ratio<1000000000000000000LL, 1LL> exa;
275
276template <class _R1, class _R2>
Howard Hinnantd397d032010-11-24 17:05:06 +0000277struct __ratio_multiply
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278{
279private:
280 static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value;
281 static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value;
282public:
283 typedef typename ratio
284 <
285 __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value,
286 __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value
287 >::type type;
288};
289
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000290#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
291
292template <class _R1, class _R2> using ratio_multiply
293 = typename __ratio_multiply<_R1, _R2>::type;
294
295#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
296
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000298struct _LIBCPP_TYPE_VIS_ONLY ratio_multiply
Howard Hinnantac417fa2010-11-28 19:41:07 +0000299 : public __ratio_multiply<_R1, _R2>::type {};
Howard Hinnantd397d032010-11-24 17:05:06 +0000300
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000301#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
302
Howard Hinnantd397d032010-11-24 17:05:06 +0000303template <class _R1, class _R2>
304struct __ratio_divide
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305{
306private:
307 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
308 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
309public:
310 typedef typename ratio
311 <
312 __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
313 __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
314 >::type type;
315};
316
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000317#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
318
319template <class _R1, class _R2> using ratio_divide
320 = typename __ratio_divide<_R1, _R2>::type;
321
322#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
323
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000325struct _LIBCPP_TYPE_VIS_ONLY ratio_divide
Howard Hinnantac417fa2010-11-28 19:41:07 +0000326 : public __ratio_divide<_R1, _R2>::type {};
Howard Hinnantd397d032010-11-24 17:05:06 +0000327
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000328#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
329
Howard Hinnantd397d032010-11-24 17:05:06 +0000330template <class _R1, class _R2>
331struct __ratio_add
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332{
333private:
334 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
335 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
336public:
337 typedef typename ratio_multiply
338 <
339 ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>,
340 ratio
341 <
342 __ll_add
343 <
344 __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
345 __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
346 >::value,
347 _R2::den
348 >
349 >::type type;
350};
351
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000352#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
353
354template <class _R1, class _R2> using ratio_add
355 = typename __ratio_add<_R1, _R2>::type;
356
357#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
358
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000360struct _LIBCPP_TYPE_VIS_ONLY ratio_add
Howard Hinnantac417fa2010-11-28 19:41:07 +0000361 : public __ratio_add<_R1, _R2>::type {};
Howard Hinnantd397d032010-11-24 17:05:06 +0000362
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000363#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
364
Howard Hinnantd397d032010-11-24 17:05:06 +0000365template <class _R1, class _R2>
366struct __ratio_subtract
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367{
368private:
369 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
370 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
371public:
372 typedef typename ratio_multiply
373 <
374 ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>,
375 ratio
376 <
377 __ll_sub
378 <
379 __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
380 __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
381 >::value,
382 _R2::den
383 >
384 >::type type;
385};
386
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000387#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
388
389template <class _R1, class _R2> using ratio_subtract
390 = typename __ratio_subtract<_R1, _R2>::type;
391
392#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
393
Howard Hinnantd397d032010-11-24 17:05:06 +0000394template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000395struct _LIBCPP_TYPE_VIS_ONLY ratio_subtract
Howard Hinnantac417fa2010-11-28 19:41:07 +0000396 : public __ratio_subtract<_R1, _R2>::type {};
Howard Hinnantd397d032010-11-24 17:05:06 +0000397
Howard Hinnant20eda8b2011-05-31 16:55:36 +0000398#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
399
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400// ratio_equal
401
402template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000403struct _LIBCPP_TYPE_VIS_ONLY ratio_equal
Marshall Clowe62560a2015-05-18 23:21:06 +0000404 : public _LIBCPP_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405
406template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000407struct _LIBCPP_TYPE_VIS_ONLY ratio_not_equal
Marshall Clowe62560a2015-05-18 23:21:06 +0000408 : public _LIBCPP_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409
410// ratio_less
411
412template <class _R1, class _R2, bool _Odd = false,
413 intmax_t _Q1 = _R1::num / _R1::den, intmax_t _M1 = _R1::num % _R1::den,
414 intmax_t _Q2 = _R2::num / _R2::den, intmax_t _M2 = _R2::num % _R2::den>
415struct __ratio_less1
416{
417 static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2;
418};
419
Howard Hinnant99968442011-11-29 18:15:50 +0000420template <class _R1, class _R2, bool _Odd, intmax_t _Qp>
421struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422{
423 static const bool value = false;
424};
425
Howard Hinnant99968442011-11-29 18:15:50 +0000426template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M2>
427struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428{
429 static const bool value = !_Odd;
430};
431
Howard Hinnant99968442011-11-29 18:15:50 +0000432template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1>
433struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434{
435 static const bool value = _Odd;
436};
437
Howard Hinnant99968442011-11-29 18:15:50 +0000438template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 intmax_t _M2>
Howard Hinnant99968442011-11-29 18:15:50 +0000440struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441{
442 static const bool value = __ratio_less1<ratio<_R1::den, _M1>,
443 ratio<_R2::den, _M2>, !_Odd>::value;
444};
445
446template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>::value,
447 intmax_t _S2 = __static_sign<_R2::num>::value>
448struct __ratio_less
449{
450 static const bool value = _S1 < _S2;
451};
452
453template <class _R1, class _R2>
454struct __ratio_less<_R1, _R2, 1LL, 1LL>
455{
456 static const bool value = __ratio_less1<_R1, _R2>::value;
457};
458
459template <class _R1, class _R2>
460struct __ratio_less<_R1, _R2, -1LL, -1LL>
461{
462 static const bool value = __ratio_less1<ratio<-_R2::num, _R2::den>, ratio<-_R1::num, _R1::den> >::value;
463};
464
465template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000466struct _LIBCPP_TYPE_VIS_ONLY ratio_less
Marshall Clowe62560a2015-05-18 23:21:06 +0000467 : public _LIBCPP_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468
469template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000470struct _LIBCPP_TYPE_VIS_ONLY ratio_less_equal
Marshall Clowe62560a2015-05-18 23:21:06 +0000471 : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472
473template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000474struct _LIBCPP_TYPE_VIS_ONLY ratio_greater
Marshall Clowe62560a2015-05-18 23:21:06 +0000475 : public _LIBCPP_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476
477template <class _R1, class _R2>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000478struct _LIBCPP_TYPE_VIS_ONLY ratio_greater_equal
Marshall Clowe62560a2015-05-18 23:21:06 +0000479 : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480
481template <class _R1, class _R2>
482struct __ratio_gcd
483{
484 typedef ratio<__static_gcd<_R1::num, _R2::num>::value,
485 __static_lcm<_R1::den, _R2::den>::value> type;
486};
487
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488_LIBCPP_END_NAMESPACE_STD
489
490#endif // _LIBCPP_RATIO