1227825Stheraven// -*- C++ -*- 2227825Stheraven//===---------------------------- ratio -----------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_RATIO 12227825Stheraven#define _LIBCPP_RATIO 13227825Stheraven 14227825Stheraven/* 15227825Stheraven ratio synopsis 16227825Stheraven 17227825Stheravennamespace std 18227825Stheraven{ 19227825Stheraven 20227825Stheraventemplate <intmax_t N, intmax_t D = 1> 21227825Stheravenclass ratio 22227825Stheraven{ 23227825Stheravenpublic: 24227825Stheraven static const intmax_t num; 25227825Stheraven static const intmax_t den; 26227825Stheraven typedef ratio<num, den> type; 27227825Stheraven}; 28227825Stheraven 29227825Stheraven// ratio arithmetic 30227825Stheraventemplate <class R1, class R2> using ratio_add = ...; 31227825Stheraventemplate <class R1, class R2> using ratio_subtract = ...; 32227825Stheraventemplate <class R1, class R2> using ratio_multiply = ...; 33227825Stheraventemplate <class R1, class R2> using ratio_divide = ...; 34227825Stheraven 35227825Stheraven// ratio comparison 36227825Stheraventemplate <class R1, class R2> struct ratio_equal; 37227825Stheraventemplate <class R1, class R2> struct ratio_not_equal; 38227825Stheraventemplate <class R1, class R2> struct ratio_less; 39227825Stheraventemplate <class R1, class R2> struct ratio_less_equal; 40227825Stheraventemplate <class R1, class R2> struct ratio_greater; 41227825Stheraventemplate <class R1, class R2> struct ratio_greater_equal; 42227825Stheraven 43227825Stheraven// convenience SI typedefs 44227825Stheraventypedef ratio<1, 1000000000000000000000000> yocto; // not supported 45227825Stheraventypedef ratio<1, 1000000000000000000000> zepto; // not supported 46227825Stheraventypedef ratio<1, 1000000000000000000> atto; 47227825Stheraventypedef ratio<1, 1000000000000000> femto; 48227825Stheraventypedef ratio<1, 1000000000000> pico; 49227825Stheraventypedef ratio<1, 1000000000> nano; 50227825Stheraventypedef ratio<1, 1000000> micro; 51227825Stheraventypedef ratio<1, 1000> milli; 52227825Stheraventypedef ratio<1, 100> centi; 53227825Stheraventypedef ratio<1, 10> deci; 54227825Stheraventypedef ratio< 10, 1> deca; 55227825Stheraventypedef ratio< 100, 1> hecto; 56227825Stheraventypedef ratio< 1000, 1> kilo; 57227825Stheraventypedef ratio< 1000000, 1> mega; 58227825Stheraventypedef ratio< 1000000000, 1> giga; 59227825Stheraventypedef ratio< 1000000000000, 1> tera; 60227825Stheraventypedef ratio< 1000000000000000, 1> peta; 61227825Stheraventypedef ratio< 1000000000000000000, 1> exa; 62227825Stheraventypedef ratio< 1000000000000000000000, 1> zetta; // not supported 63227825Stheraventypedef ratio<1000000000000000000000000, 1> yotta; // not supported 64227825Stheraven 65227825Stheraven} 66227825Stheraven*/ 67227825Stheraven 68227825Stheraven#include <__config> 69227825Stheraven#include <cstdint> 70227825Stheraven#include <climits> 71227825Stheraven#include <type_traits> 72227825Stheraven 73232950Stheraven#include <__undef_min_max> 74232950Stheraven 75227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 76227825Stheraven#pragma GCC system_header 77227825Stheraven#endif 78227825Stheraven 79227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 80227825Stheraven 81227825Stheraven// __static_gcd 82227825Stheraven 83227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 84227825Stheravenstruct __static_gcd 85227825Stheraven{ 86227825Stheraven static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value; 87227825Stheraven}; 88227825Stheraven 89227825Stheraventemplate <intmax_t _Xp> 90227825Stheravenstruct __static_gcd<_Xp, 0> 91227825Stheraven{ 92227825Stheraven static const intmax_t value = _Xp; 93227825Stheraven}; 94227825Stheraven 95227825Stheraventemplate <> 96227825Stheravenstruct __static_gcd<0, 0> 97227825Stheraven{ 98227825Stheraven static const intmax_t value = 1; 99227825Stheraven}; 100227825Stheraven 101227825Stheraven// __static_lcm 102227825Stheraven 103227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 104227825Stheravenstruct __static_lcm 105227825Stheraven{ 106227825Stheraven static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp; 107227825Stheraven}; 108227825Stheraven 109227825Stheraventemplate <intmax_t _Xp> 110227825Stheravenstruct __static_abs 111227825Stheraven{ 112227825Stheraven static const intmax_t value = _Xp < 0 ? -_Xp : _Xp; 113227825Stheraven}; 114227825Stheraven 115227825Stheraventemplate <intmax_t _Xp> 116227825Stheravenstruct __static_sign 117227825Stheraven{ 118227825Stheraven static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1); 119227825Stheraven}; 120227825Stheraven 121227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value> 122227825Stheravenclass __ll_add; 123227825Stheraven 124227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 125227825Stheravenclass __ll_add<_Xp, _Yp, 1> 126227825Stheraven{ 127227825Stheraven static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; 128227825Stheraven static const intmax_t max = -min; 129227825Stheraven 130227825Stheraven static_assert(_Xp <= max - _Yp, "overflow in __ll_add"); 131227825Stheravenpublic: 132227825Stheraven static const intmax_t value = _Xp + _Yp; 133227825Stheraven}; 134227825Stheraven 135227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 136227825Stheravenclass __ll_add<_Xp, _Yp, 0> 137227825Stheraven{ 138227825Stheravenpublic: 139227825Stheraven static const intmax_t value = _Xp; 140227825Stheraven}; 141227825Stheraven 142227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 143227825Stheravenclass __ll_add<_Xp, _Yp, -1> 144227825Stheraven{ 145227825Stheraven static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; 146227825Stheraven static const intmax_t max = -min; 147227825Stheraven 148227825Stheraven static_assert(min - _Yp <= _Xp, "overflow in __ll_add"); 149227825Stheravenpublic: 150227825Stheraven static const intmax_t value = _Xp + _Yp; 151227825Stheraven}; 152227825Stheraven 153227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value> 154227825Stheravenclass __ll_sub; 155227825Stheraven 156227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 157227825Stheravenclass __ll_sub<_Xp, _Yp, 1> 158227825Stheraven{ 159227825Stheraven static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; 160227825Stheraven static const intmax_t max = -min; 161227825Stheraven 162227825Stheraven static_assert(min + _Yp <= _Xp, "overflow in __ll_sub"); 163227825Stheravenpublic: 164227825Stheraven static const intmax_t value = _Xp - _Yp; 165227825Stheraven}; 166227825Stheraven 167227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 168227825Stheravenclass __ll_sub<_Xp, _Yp, 0> 169227825Stheraven{ 170227825Stheravenpublic: 171227825Stheraven static const intmax_t value = _Xp; 172227825Stheraven}; 173227825Stheraven 174227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 175227825Stheravenclass __ll_sub<_Xp, _Yp, -1> 176227825Stheraven{ 177227825Stheraven static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; 178227825Stheraven static const intmax_t max = -min; 179227825Stheraven 180227825Stheraven static_assert(_Xp <= max + _Yp, "overflow in __ll_sub"); 181227825Stheravenpublic: 182227825Stheraven static const intmax_t value = _Xp - _Yp; 183227825Stheraven}; 184227825Stheraven 185227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 186227825Stheravenclass __ll_mul 187227825Stheraven{ 188227825Stheraven static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); 189227825Stheraven static const intmax_t min = nan + 1; 190227825Stheraven static const intmax_t max = -min; 191227825Stheraven static const intmax_t __a_x = __static_abs<_Xp>::value; 192227825Stheraven static const intmax_t __a_y = __static_abs<_Yp>::value; 193227825Stheraven 194227825Stheraven static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul"); 195227825Stheravenpublic: 196227825Stheraven static const intmax_t value = _Xp * _Yp; 197227825Stheraven}; 198227825Stheraven 199227825Stheraventemplate <intmax_t _Yp> 200227825Stheravenclass __ll_mul<0, _Yp> 201227825Stheraven{ 202227825Stheravenpublic: 203227825Stheraven static const intmax_t value = 0; 204227825Stheraven}; 205227825Stheraven 206227825Stheraventemplate <intmax_t _Xp> 207227825Stheravenclass __ll_mul<_Xp, 0> 208227825Stheraven{ 209227825Stheravenpublic: 210227825Stheraven static const intmax_t value = 0; 211227825Stheraven}; 212227825Stheraven 213227825Stheraventemplate <> 214227825Stheravenclass __ll_mul<0, 0> 215227825Stheraven{ 216227825Stheravenpublic: 217227825Stheraven static const intmax_t value = 0; 218227825Stheraven}; 219227825Stheraven 220227825Stheraven// Not actually used but left here in case needed in future maintenance 221227825Stheraventemplate <intmax_t _Xp, intmax_t _Yp> 222227825Stheravenclass __ll_div 223227825Stheraven{ 224227825Stheraven static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); 225227825Stheraven static const intmax_t min = nan + 1; 226227825Stheraven static const intmax_t max = -min; 227227825Stheraven 228227825Stheraven static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div"); 229227825Stheravenpublic: 230227825Stheraven static const intmax_t value = _Xp / _Yp; 231227825Stheraven}; 232227825Stheraven 233227825Stheraventemplate <intmax_t _Num, intmax_t _Den = 1> 234262801Sdimclass _LIBCPP_TYPE_VIS_ONLY ratio 235227825Stheraven{ 236227825Stheraven static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range"); 237227825Stheraven static_assert(_Den != 0, "ratio divide by 0"); 238227825Stheraven static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range"); 239227825Stheraven static const intmax_t __na = __static_abs<_Num>::value; 240227825Stheraven static const intmax_t __da = __static_abs<_Den>::value; 241227825Stheraven static const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value; 242227825Stheraven static const intmax_t __gcd = __static_gcd<__na, __da>::value; 243227825Stheravenpublic: 244227825Stheraven static const intmax_t num = __s * __na / __gcd; 245227825Stheraven static const intmax_t den = __da / __gcd; 246227825Stheraven 247227825Stheraven typedef ratio<num, den> type; 248227825Stheraven}; 249227825Stheraven 250227825Stheraventemplate <intmax_t _Num, intmax_t _Den> const intmax_t ratio<_Num, _Den>::num; 251227825Stheraventemplate <intmax_t _Num, intmax_t _Den> const intmax_t ratio<_Num, _Den>::den; 252227825Stheraven 253227825Stheraventemplate <class _Tp> struct __is_ratio : false_type {}; 254227825Stheraventemplate <intmax_t _Num, intmax_t _Den> struct __is_ratio<ratio<_Num, _Den> > : true_type {}; 255227825Stheraven 256227825Stheraventypedef ratio<1LL, 1000000000000000000LL> atto; 257227825Stheraventypedef ratio<1LL, 1000000000000000LL> femto; 258227825Stheraventypedef ratio<1LL, 1000000000000LL> pico; 259227825Stheraventypedef ratio<1LL, 1000000000LL> nano; 260227825Stheraventypedef ratio<1LL, 1000000LL> micro; 261227825Stheraventypedef ratio<1LL, 1000LL> milli; 262227825Stheraventypedef ratio<1LL, 100LL> centi; 263227825Stheraventypedef ratio<1LL, 10LL> deci; 264227825Stheraventypedef ratio< 10LL, 1LL> deca; 265227825Stheraventypedef ratio< 100LL, 1LL> hecto; 266227825Stheraventypedef ratio< 1000LL, 1LL> kilo; 267227825Stheraventypedef ratio< 1000000LL, 1LL> mega; 268227825Stheraventypedef ratio< 1000000000LL, 1LL> giga; 269227825Stheraventypedef ratio< 1000000000000LL, 1LL> tera; 270227825Stheraventypedef ratio< 1000000000000000LL, 1LL> peta; 271227825Stheraventypedef ratio<1000000000000000000LL, 1LL> exa; 272227825Stheraven 273227825Stheraventemplate <class _R1, class _R2> 274227825Stheravenstruct __ratio_multiply 275227825Stheraven{ 276227825Stheravenprivate: 277227825Stheraven static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value; 278227825Stheraven static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value; 279227825Stheravenpublic: 280227825Stheraven typedef typename ratio 281227825Stheraven < 282227825Stheraven __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value, 283227825Stheraven __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value 284227825Stheraven >::type type; 285227825Stheraven}; 286227825Stheraven 287227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 288227825Stheraven 289227825Stheraventemplate <class _R1, class _R2> using ratio_multiply 290227825Stheraven = typename __ratio_multiply<_R1, _R2>::type; 291227825Stheraven 292227825Stheraven#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 293227825Stheraven 294227825Stheraventemplate <class _R1, class _R2> 295262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_multiply 296227825Stheraven : public __ratio_multiply<_R1, _R2>::type {}; 297227825Stheraven 298227825Stheraven#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 299227825Stheraven 300227825Stheraventemplate <class _R1, class _R2> 301227825Stheravenstruct __ratio_divide 302227825Stheraven{ 303227825Stheravenprivate: 304227825Stheraven static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; 305227825Stheraven static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; 306227825Stheravenpublic: 307227825Stheraven typedef typename ratio 308227825Stheraven < 309227825Stheraven __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, 310227825Stheraven __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value 311227825Stheraven >::type type; 312227825Stheraven}; 313227825Stheraven 314227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 315227825Stheraven 316227825Stheraventemplate <class _R1, class _R2> using ratio_divide 317227825Stheraven = typename __ratio_divide<_R1, _R2>::type; 318227825Stheraven 319227825Stheraven#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 320227825Stheraven 321227825Stheraventemplate <class _R1, class _R2> 322262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_divide 323227825Stheraven : public __ratio_divide<_R1, _R2>::type {}; 324227825Stheraven 325227825Stheraven#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 326227825Stheraven 327227825Stheraventemplate <class _R1, class _R2> 328227825Stheravenstruct __ratio_add 329227825Stheraven{ 330227825Stheravenprivate: 331227825Stheraven static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; 332227825Stheraven static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; 333227825Stheravenpublic: 334227825Stheraven typedef typename ratio_multiply 335227825Stheraven < 336227825Stheraven ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, 337227825Stheraven ratio 338227825Stheraven < 339227825Stheraven __ll_add 340227825Stheraven < 341227825Stheraven __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, 342227825Stheraven __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value 343227825Stheraven >::value, 344227825Stheraven _R2::den 345227825Stheraven > 346227825Stheraven >::type type; 347227825Stheraven}; 348227825Stheraven 349227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 350227825Stheraven 351227825Stheraventemplate <class _R1, class _R2> using ratio_add 352227825Stheraven = typename __ratio_add<_R1, _R2>::type; 353227825Stheraven 354227825Stheraven#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 355227825Stheraven 356227825Stheraventemplate <class _R1, class _R2> 357262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_add 358227825Stheraven : public __ratio_add<_R1, _R2>::type {}; 359227825Stheraven 360227825Stheraven#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 361227825Stheraven 362227825Stheraventemplate <class _R1, class _R2> 363227825Stheravenstruct __ratio_subtract 364227825Stheraven{ 365227825Stheravenprivate: 366227825Stheraven static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; 367227825Stheraven static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; 368227825Stheravenpublic: 369227825Stheraven typedef typename ratio_multiply 370227825Stheraven < 371227825Stheraven ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, 372227825Stheraven ratio 373227825Stheraven < 374227825Stheraven __ll_sub 375227825Stheraven < 376227825Stheraven __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, 377227825Stheraven __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value 378227825Stheraven >::value, 379227825Stheraven _R2::den 380227825Stheraven > 381227825Stheraven >::type type; 382227825Stheraven}; 383227825Stheraven 384227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 385227825Stheraven 386227825Stheraventemplate <class _R1, class _R2> using ratio_subtract 387227825Stheraven = typename __ratio_subtract<_R1, _R2>::type; 388227825Stheraven 389227825Stheraven#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 390227825Stheraven 391227825Stheraventemplate <class _R1, class _R2> 392262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_subtract 393227825Stheraven : public __ratio_subtract<_R1, _R2>::type {}; 394227825Stheraven 395227825Stheraven#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 396227825Stheraven 397227825Stheraven// ratio_equal 398227825Stheraven 399227825Stheraventemplate <class _R1, class _R2> 400262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_equal 401227825Stheraven : public integral_constant<bool, _R1::num == _R2::num && _R1::den == _R2::den> {}; 402227825Stheraven 403227825Stheraventemplate <class _R1, class _R2> 404262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_not_equal 405227825Stheraven : public integral_constant<bool, !ratio_equal<_R1, _R2>::value> {}; 406227825Stheraven 407227825Stheraven// ratio_less 408227825Stheraven 409227825Stheraventemplate <class _R1, class _R2, bool _Odd = false, 410227825Stheraven intmax_t _Q1 = _R1::num / _R1::den, intmax_t _M1 = _R1::num % _R1::den, 411227825Stheraven intmax_t _Q2 = _R2::num / _R2::den, intmax_t _M2 = _R2::num % _R2::den> 412227825Stheravenstruct __ratio_less1 413227825Stheraven{ 414227825Stheraven static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2; 415227825Stheraven}; 416227825Stheraven 417232950Stheraventemplate <class _R1, class _R2, bool _Odd, intmax_t _Qp> 418232950Stheravenstruct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0> 419227825Stheraven{ 420227825Stheraven static const bool value = false; 421227825Stheraven}; 422227825Stheraven 423232950Stheraventemplate <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M2> 424232950Stheravenstruct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2> 425227825Stheraven{ 426227825Stheraven static const bool value = !_Odd; 427227825Stheraven}; 428227825Stheraven 429232950Stheraventemplate <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1> 430232950Stheravenstruct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0> 431227825Stheraven{ 432227825Stheraven static const bool value = _Odd; 433227825Stheraven}; 434227825Stheraven 435232950Stheraventemplate <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1, 436227825Stheraven intmax_t _M2> 437232950Stheravenstruct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2> 438227825Stheraven{ 439227825Stheraven static const bool value = __ratio_less1<ratio<_R1::den, _M1>, 440227825Stheraven ratio<_R2::den, _M2>, !_Odd>::value; 441227825Stheraven}; 442227825Stheraven 443227825Stheraventemplate <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>::value, 444227825Stheraven intmax_t _S2 = __static_sign<_R2::num>::value> 445227825Stheravenstruct __ratio_less 446227825Stheraven{ 447227825Stheraven static const bool value = _S1 < _S2; 448227825Stheraven}; 449227825Stheraven 450227825Stheraventemplate <class _R1, class _R2> 451227825Stheravenstruct __ratio_less<_R1, _R2, 1LL, 1LL> 452227825Stheraven{ 453227825Stheraven static const bool value = __ratio_less1<_R1, _R2>::value; 454227825Stheraven}; 455227825Stheraven 456227825Stheraventemplate <class _R1, class _R2> 457227825Stheravenstruct __ratio_less<_R1, _R2, -1LL, -1LL> 458227825Stheraven{ 459227825Stheraven static const bool value = __ratio_less1<ratio<-_R2::num, _R2::den>, ratio<-_R1::num, _R1::den> >::value; 460227825Stheraven}; 461227825Stheraven 462227825Stheraventemplate <class _R1, class _R2> 463262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_less 464227825Stheraven : public integral_constant<bool, __ratio_less<_R1, _R2>::value> {}; 465227825Stheraven 466227825Stheraventemplate <class _R1, class _R2> 467262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_less_equal 468227825Stheraven : public integral_constant<bool, !ratio_less<_R2, _R1>::value> {}; 469227825Stheraven 470227825Stheraventemplate <class _R1, class _R2> 471262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_greater 472227825Stheraven : public integral_constant<bool, ratio_less<_R2, _R1>::value> {}; 473227825Stheraven 474227825Stheraventemplate <class _R1, class _R2> 475262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY ratio_greater_equal 476227825Stheraven : public integral_constant<bool, !ratio_less<_R1, _R2>::value> {}; 477227825Stheraven 478227825Stheraventemplate <class _R1, class _R2> 479227825Stheravenstruct __ratio_gcd 480227825Stheraven{ 481227825Stheraven typedef ratio<__static_gcd<_R1::num, _R2::num>::value, 482227825Stheraven __static_lcm<_R1::den, _R2::den>::value> type; 483227825Stheraven}; 484227825Stheraven 485227825Stheraven_LIBCPP_END_NAMESPACE_STD 486227825Stheraven 487227825Stheraven#endif // _LIBCPP_RATIO 488