| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_RATIO |
| 11 | #define _LIBCPP_RATIO |
| 12 | |
| 13 | /* |
| 14 | ratio synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <intmax_t N, intmax_t D = 1> |
| 20 | class ratio |
| 21 | { |
| 22 | public: |
| 23 | static constexpr intmax_t num; |
| 24 | static constexpr intmax_t den; |
| 25 | typedef ratio<num, den> type; |
| 26 | }; |
| 27 | |
| 28 | // ratio arithmetic |
| 29 | template <class R1, class R2> using ratio_add = ...; |
| 30 | template <class R1, class R2> using ratio_subtract = ...; |
| 31 | template <class R1, class R2> using ratio_multiply = ...; |
| 32 | template <class R1, class R2> using ratio_divide = ...; |
| 33 | |
| 34 | // ratio comparison |
| 35 | template <class R1, class R2> struct ratio_equal; |
| 36 | template <class R1, class R2> struct ratio_not_equal; |
| 37 | template <class R1, class R2> struct ratio_less; |
| 38 | template <class R1, class R2> struct ratio_less_equal; |
| 39 | template <class R1, class R2> struct ratio_greater; |
| 40 | template <class R1, class R2> struct ratio_greater_equal; |
| 41 | |
| 42 | // convenience SI typedefs |
| 43 | using quecto = ratio <1, 1'000'000'000'000'000'000'000'000'000'000>; // Since C++26; not supported |
| 44 | using ronto = ratio <1, 1'000'000'000'000'000'000'000'000'000>; // Since C++26; not supported |
| 45 | typedef ratio<1, 1000000000000000000000000> yocto; // not supported |
| 46 | typedef ratio<1, 1000000000000000000000> zepto; // not supported |
| 47 | typedef ratio<1, 1000000000000000000> atto; |
| 48 | typedef ratio<1, 1000000000000000> femto; |
| 49 | typedef ratio<1, 1000000000000> pico; |
| 50 | typedef ratio<1, 1000000000> nano; |
| 51 | typedef ratio<1, 1000000> micro; |
| 52 | typedef ratio<1, 1000> milli; |
| 53 | typedef ratio<1, 100> centi; |
| 54 | typedef ratio<1, 10> deci; |
| 55 | typedef ratio< 10, 1> deca; |
| 56 | typedef ratio< 100, 1> hecto; |
| 57 | typedef ratio< 1000, 1> kilo; |
| 58 | typedef ratio< 1000000, 1> mega; |
| 59 | typedef ratio< 1000000000, 1> giga; |
| 60 | typedef ratio< 1000000000000, 1> tera; |
| 61 | typedef ratio< 1000000000000000, 1> peta; |
| 62 | typedef ratio< 1000000000000000000, 1> exa; |
| 63 | typedef ratio< 1000000000000000000000, 1> zetta; // not supported |
| 64 | typedef ratio<1000000000000000000000000, 1> yotta; // not supported |
| 65 | using ronna = ratio <1'000'000'000'000'000'000'000'000'000, 1>; // Since C++26; not supported |
| 66 | using quetta = ratio <1'000'000'000'000'000'000'000'000'000'000, 1>; // Since C++26; not supported |
| 67 | |
| 68 | // 20.11.5, ratio comparison |
| 69 | template <class R1, class R2> inline constexpr bool ratio_equal_v |
| 70 | = ratio_equal<R1, R2>::value; // C++17 |
| 71 | template <class R1, class R2> inline constexpr bool ratio_not_equal_v |
| 72 | = ratio_not_equal<R1, R2>::value; // C++17 |
| 73 | template <class R1, class R2> inline constexpr bool ratio_less_v |
| 74 | = ratio_less<R1, R2>::value; // C++17 |
| 75 | template <class R1, class R2> inline constexpr bool ratio_less_equal_v |
| 76 | = ratio_less_equal<R1, R2>::value; // C++17 |
| 77 | template <class R1, class R2> inline constexpr bool ratio_greater_v |
| 78 | = ratio_greater<R1, R2>::value; // C++17 |
| 79 | template <class R1, class R2> inline constexpr bool ratio_greater_equal_v |
| 80 | = ratio_greater_equal<R1, R2>::value; // C++17 |
| 81 | } |
| 82 | */ |
| 83 | |
| 84 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 85 | # include <__cxx03/ratio> |
| 86 | #else |
| 87 | # include <__config> |
| 88 | # include <__type_traits/integral_constant.h> |
| 89 | # include <climits> |
| 90 | # include <cstdint> |
| 91 | # include <version> |
| 92 | |
| 93 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 94 | # pragma GCC system_header |
| 95 | # endif |
| 96 | |
| 97 | _LIBCPP_PUSH_MACROS |
| 98 | # include <__undef_macros> |
| 99 | |
| 100 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 101 | |
| 102 | // __static_gcd |
| 103 | |
| 104 | template <intmax_t _Xp, intmax_t _Yp> |
| 105 | inline const intmax_t __static_gcd = __static_gcd<_Yp, _Xp % _Yp>; |
| 106 | |
| 107 | template <intmax_t _Xp> |
| 108 | inline const intmax_t __static_gcd<_Xp, 0> = _Xp; |
| 109 | |
| 110 | template <> |
| 111 | inline const intmax_t __static_gcd<0, 0> = 1; |
| 112 | |
| 113 | // __static_lcm |
| 114 | |
| 115 | template <intmax_t _Xp, intmax_t _Yp> |
| 116 | inline const intmax_t __static_lcm = _Xp / __static_gcd<_Xp, _Yp> * _Yp; |
| 117 | |
| 118 | template <intmax_t _Xp> |
| 119 | inline const intmax_t __static_abs = _Xp < 0 ? -_Xp : _Xp; |
| 120 | |
| 121 | template <intmax_t _Xp> |
| 122 | inline const intmax_t __static_sign = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1); |
| 123 | |
| 124 | template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> > |
| 125 | class __ll_add; |
| 126 | |
| 127 | template <intmax_t _Xp, intmax_t _Yp> |
| 128 | class __ll_add<_Xp, _Yp, 1> { |
| 129 | static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; |
| 130 | static const intmax_t max = -min; |
| 131 | |
| 132 | static_assert(_Xp <= max - _Yp, "overflow in __ll_add" ); |
| 133 | |
| 134 | public: |
| 135 | static const intmax_t value = _Xp + _Yp; |
| 136 | }; |
| 137 | |
| 138 | template <intmax_t _Xp, intmax_t _Yp> |
| 139 | class __ll_add<_Xp, _Yp, 0> { |
| 140 | public: |
| 141 | static const intmax_t value = _Xp; |
| 142 | }; |
| 143 | |
| 144 | template <intmax_t _Xp, intmax_t _Yp> |
| 145 | class __ll_add<_Xp, _Yp, -1> { |
| 146 | static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; |
| 147 | static const intmax_t max = -min; |
| 148 | |
| 149 | static_assert(min - _Yp <= _Xp, "overflow in __ll_add" ); |
| 150 | |
| 151 | public: |
| 152 | static const intmax_t value = _Xp + _Yp; |
| 153 | }; |
| 154 | |
| 155 | template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> > |
| 156 | class __ll_sub; |
| 157 | |
| 158 | template <intmax_t _Xp, intmax_t _Yp> |
| 159 | class __ll_sub<_Xp, _Yp, 1> { |
| 160 | static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; |
| 161 | static const intmax_t max = -min; |
| 162 | |
| 163 | static_assert(min + _Yp <= _Xp, "overflow in __ll_sub" ); |
| 164 | |
| 165 | public: |
| 166 | static const intmax_t value = _Xp - _Yp; |
| 167 | }; |
| 168 | |
| 169 | template <intmax_t _Xp, intmax_t _Yp> |
| 170 | class __ll_sub<_Xp, _Yp, 0> { |
| 171 | public: |
| 172 | static const intmax_t value = _Xp; |
| 173 | }; |
| 174 | |
| 175 | template <intmax_t _Xp, intmax_t _Yp> |
| 176 | class __ll_sub<_Xp, _Yp, -1> { |
| 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" ); |
| 181 | |
| 182 | public: |
| 183 | static const intmax_t value = _Xp - _Yp; |
| 184 | }; |
| 185 | |
| 186 | template <intmax_t _Xp, intmax_t _Yp> |
| 187 | class __ll_mul { |
| 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>; |
| 192 | static const intmax_t __a_y = __static_abs<_Yp>; |
| 193 | |
| 194 | static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul" ); |
| 195 | |
| 196 | public: |
| 197 | static const intmax_t value = _Xp * _Yp; |
| 198 | }; |
| 199 | |
| 200 | template <intmax_t _Yp> |
| 201 | class __ll_mul<0, _Yp> { |
| 202 | public: |
| 203 | static const intmax_t value = 0; |
| 204 | }; |
| 205 | |
| 206 | template <intmax_t _Xp> |
| 207 | class __ll_mul<_Xp, 0> { |
| 208 | public: |
| 209 | static const intmax_t value = 0; |
| 210 | }; |
| 211 | |
| 212 | template <> |
| 213 | class __ll_mul<0, 0> { |
| 214 | public: |
| 215 | static const intmax_t value = 0; |
| 216 | }; |
| 217 | |
| 218 | // Not actually used but left here in case needed in future maintenance |
| 219 | template <intmax_t _Xp, intmax_t _Yp> |
| 220 | class __ll_div { |
| 221 | static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); |
| 222 | static const intmax_t min = nan + 1; |
| 223 | static const intmax_t max = -min; |
| 224 | |
| 225 | static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div" ); |
| 226 | |
| 227 | public: |
| 228 | static const intmax_t value = _Xp / _Yp; |
| 229 | }; |
| 230 | |
| 231 | template <intmax_t _Num, intmax_t _Den = 1> |
| 232 | class ratio { |
| 233 | static_assert(__static_abs<_Num> >= 0, "ratio numerator is out of range" ); |
| 234 | static_assert(_Den != 0, "ratio divide by 0" ); |
| 235 | static_assert(__static_abs<_Den> > 0, "ratio denominator is out of range" ); |
| 236 | static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>; |
| 237 | static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>; |
| 238 | static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num> * __static_sign<_Den>; |
| 239 | static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>; |
| 240 | |
| 241 | public: |
| 242 | static inline _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd; |
| 243 | static inline _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd; |
| 244 | |
| 245 | typedef ratio<num, den> type; |
| 246 | }; |
| 247 | |
| 248 | template <class _Tp> |
| 249 | inline const bool __is_ratio_v = false; |
| 250 | |
| 251 | template <intmax_t _Num, intmax_t _Den> |
| 252 | inline const bool __is_ratio_v<ratio<_Num, _Den> > = true; |
| 253 | |
| 254 | typedef ratio<1LL, 1000000000000000000LL> atto; |
| 255 | typedef ratio<1LL, 1000000000000000LL> femto; |
| 256 | typedef ratio<1LL, 1000000000000LL> pico; |
| 257 | typedef ratio<1LL, 1000000000LL> nano; |
| 258 | typedef ratio<1LL, 1000000LL> micro; |
| 259 | typedef ratio<1LL, 1000LL> milli; |
| 260 | typedef ratio<1LL, 100LL> centi; |
| 261 | typedef ratio<1LL, 10LL> deci; |
| 262 | typedef ratio< 10LL, 1LL> deca; |
| 263 | typedef ratio< 100LL, 1LL> hecto; |
| 264 | typedef ratio< 1000LL, 1LL> kilo; |
| 265 | typedef ratio< 1000000LL, 1LL> mega; |
| 266 | typedef ratio< 1000000000LL, 1LL> giga; |
| 267 | typedef ratio< 1000000000000LL, 1LL> tera; |
| 268 | typedef ratio< 1000000000000000LL, 1LL> peta; |
| 269 | typedef ratio<1000000000000000000LL, 1LL> exa; |
| 270 | |
| 271 | template <class _R1, class _R2> |
| 272 | struct __ratio_multiply { |
| 273 | private: |
| 274 | static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>; |
| 275 | static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>; |
| 276 | |
| 277 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 278 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 279 | |
| 280 | public: |
| 281 | typedef typename ratio< __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value, |
| 282 | __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value >::type type; |
| 283 | }; |
| 284 | |
| 285 | # ifndef _LIBCPP_CXX03_LANG |
| 286 | |
| 287 | template <class _R1, class _R2> |
| 288 | using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type; |
| 289 | |
| 290 | # else // _LIBCPP_CXX03_LANG |
| 291 | |
| 292 | template <class _R1, class _R2> |
| 293 | struct ratio_multiply : public __ratio_multiply<_R1, _R2>::type {}; |
| 294 | |
| 295 | # endif // _LIBCPP_CXX03_LANG |
| 296 | |
| 297 | template <class _R1, class _R2> |
| 298 | struct __ratio_divide { |
| 299 | private: |
| 300 | static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>; |
| 301 | static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>; |
| 302 | |
| 303 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 304 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 305 | |
| 306 | public: |
| 307 | typedef typename ratio< __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, |
| 308 | __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value >::type type; |
| 309 | }; |
| 310 | |
| 311 | # ifndef _LIBCPP_CXX03_LANG |
| 312 | |
| 313 | template <class _R1, class _R2> |
| 314 | using ratio_divide = typename __ratio_divide<_R1, _R2>::type; |
| 315 | |
| 316 | # else // _LIBCPP_CXX03_LANG |
| 317 | |
| 318 | template <class _R1, class _R2> |
| 319 | struct ratio_divide : public __ratio_divide<_R1, _R2>::type {}; |
| 320 | |
| 321 | # endif // _LIBCPP_CXX03_LANG |
| 322 | |
| 323 | template <class _R1, class _R2> |
| 324 | struct __ratio_add { |
| 325 | private: |
| 326 | static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>; |
| 327 | static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>; |
| 328 | |
| 329 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 330 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 331 | |
| 332 | public: |
| 333 | typedef typename ratio_multiply< |
| 334 | ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, |
| 335 | ratio< __ll_add< __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, |
| 336 | __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value >::value, |
| 337 | _R2::den > >::type type; |
| 338 | }; |
| 339 | |
| 340 | # ifndef _LIBCPP_CXX03_LANG |
| 341 | |
| 342 | template <class _R1, class _R2> |
| 343 | using ratio_add = typename __ratio_add<_R1, _R2>::type; |
| 344 | |
| 345 | # else // _LIBCPP_CXX03_LANG |
| 346 | |
| 347 | template <class _R1, class _R2> |
| 348 | struct ratio_add : public __ratio_add<_R1, _R2>::type {}; |
| 349 | |
| 350 | # endif // _LIBCPP_CXX03_LANG |
| 351 | |
| 352 | template <class _R1, class _R2> |
| 353 | struct __ratio_subtract { |
| 354 | private: |
| 355 | static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>; |
| 356 | static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>; |
| 357 | |
| 358 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 359 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 360 | |
| 361 | public: |
| 362 | typedef typename ratio_multiply< |
| 363 | ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, |
| 364 | ratio< __ll_sub< __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, |
| 365 | __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value >::value, |
| 366 | _R2::den > >::type type; |
| 367 | }; |
| 368 | |
| 369 | # ifndef _LIBCPP_CXX03_LANG |
| 370 | |
| 371 | template <class _R1, class _R2> |
| 372 | using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type; |
| 373 | |
| 374 | # else // _LIBCPP_CXX03_LANG |
| 375 | |
| 376 | template <class _R1, class _R2> |
| 377 | struct ratio_subtract : public __ratio_subtract<_R1, _R2>::type {}; |
| 378 | |
| 379 | # endif // _LIBCPP_CXX03_LANG |
| 380 | |
| 381 | // ratio_equal |
| 382 | |
| 383 | template <class _R1, class _R2> |
| 384 | struct ratio_equal : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> { |
| 385 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 386 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 387 | }; |
| 388 | |
| 389 | template <class _R1, class _R2> |
| 390 | struct ratio_not_equal : _BoolConstant<!ratio_equal<_R1, _R2>::value> { |
| 391 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 392 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 393 | }; |
| 394 | |
| 395 | // ratio_less |
| 396 | |
| 397 | template <class _R1, |
| 398 | class _R2, |
| 399 | bool _Odd = false, |
| 400 | intmax_t _Q1 = _R1::num / _R1::den, |
| 401 | intmax_t _M1 = _R1::num % _R1::den, |
| 402 | intmax_t _Q2 = _R2::num / _R2::den, |
| 403 | intmax_t _M2 = _R2::num % _R2::den> |
| 404 | struct __ratio_less1 { |
| 405 | static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2; |
| 406 | }; |
| 407 | |
| 408 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp> |
| 409 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0> { |
| 410 | static const bool value = false; |
| 411 | }; |
| 412 | |
| 413 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M2> |
| 414 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2> { |
| 415 | static const bool value = !_Odd; |
| 416 | }; |
| 417 | |
| 418 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1> |
| 419 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0> { |
| 420 | static const bool value = _Odd; |
| 421 | }; |
| 422 | |
| 423 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1, intmax_t _M2> |
| 424 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2> { |
| 425 | static const bool value = __ratio_less1<ratio<_R1::den, _M1>, ratio<_R2::den, _M2>, !_Odd>::value; |
| 426 | }; |
| 427 | |
| 428 | template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>, intmax_t _S2 = __static_sign<_R2::num> > |
| 429 | struct __ratio_less { |
| 430 | static const bool value = _S1 < _S2; |
| 431 | }; |
| 432 | |
| 433 | template <class _R1, class _R2> |
| 434 | struct __ratio_less<_R1, _R2, 1LL, 1LL> { |
| 435 | static const bool value = __ratio_less1<_R1, _R2>::value; |
| 436 | }; |
| 437 | |
| 438 | template <class _R1, class _R2> |
| 439 | struct __ratio_less<_R1, _R2, -1LL, -1LL> { |
| 440 | static const bool value = __ratio_less1<ratio<-_R2::num, _R2::den>, ratio<-_R1::num, _R1::den> >::value; |
| 441 | }; |
| 442 | |
| 443 | template <class _R1, class _R2> |
| 444 | struct ratio_less : _BoolConstant<__ratio_less<_R1, _R2>::value> { |
| 445 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 446 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 447 | }; |
| 448 | |
| 449 | template <class _R1, class _R2> |
| 450 | struct ratio_less_equal : _BoolConstant<!ratio_less<_R2, _R1>::value> { |
| 451 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 452 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 453 | }; |
| 454 | |
| 455 | template <class _R1, class _R2> |
| 456 | struct ratio_greater : _BoolConstant<ratio_less<_R2, _R1>::value> { |
| 457 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 458 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 459 | }; |
| 460 | |
| 461 | template <class _R1, class _R2> |
| 462 | struct ratio_greater_equal : _BoolConstant<!ratio_less<_R1, _R2>::value> { |
| 463 | static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template" ); |
| 464 | static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template" ); |
| 465 | }; |
| 466 | |
| 467 | template <class _R1, class _R2> |
| 468 | using __ratio_gcd _LIBCPP_NODEBUG = ratio<__static_gcd<_R1::num, _R2::num>, __static_lcm<_R1::den, _R2::den> >; |
| 469 | |
| 470 | # if _LIBCPP_STD_VER >= 17 |
| 471 | template <class _R1, class _R2> |
| 472 | inline constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value; |
| 473 | |
| 474 | template <class _R1, class _R2> |
| 475 | inline constexpr bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value; |
| 476 | |
| 477 | template <class _R1, class _R2> |
| 478 | inline constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value; |
| 479 | |
| 480 | template <class _R1, class _R2> |
| 481 | inline constexpr bool ratio_less_equal_v = ratio_less_equal<_R1, _R2>::value; |
| 482 | |
| 483 | template <class _R1, class _R2> |
| 484 | inline constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value; |
| 485 | |
| 486 | template <class _R1, class _R2> |
| 487 | inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value; |
| 488 | # endif |
| 489 | |
| 490 | _LIBCPP_END_NAMESPACE_STD |
| 491 | |
| 492 | _LIBCPP_POP_MACROS |
| 493 | |
| 494 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 495 | # include <type_traits> |
| 496 | # endif |
| 497 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 498 | |
| 499 | #endif // _LIBCPP_RATIO |
| 500 | |