Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | eb8650a | 2021-11-17 21:25:01 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 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: |
Marshall Clow | 60d5e0e | 2015-04-16 21:36:54 | [diff] [blame] | 23 | static constexpr intmax_t num; |
| 24 | static constexpr intmax_t den; |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 25 | typedef ratio<num, den> type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | // ratio arithmetic |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 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 = ...; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 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 |
Mark de Wever | f805c79 | 2023-06-17 13:50:50 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 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 |
Mark de Wever | f805c79 | 2023-06-17 13:50:50 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 67 | |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 68 | // 20.11.5, ratio comparison |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 69 | template <class R1, class R2> inline constexpr bool ratio_equal_v |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 70 | = ratio_equal<R1, R2>::value; // C++17 |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 71 | template <class R1, class R2> inline constexpr bool ratio_not_equal_v |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 72 | = ratio_not_equal<R1, R2>::value; // C++17 |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 73 | template <class R1, class R2> inline constexpr bool ratio_less_v |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 74 | = ratio_less<R1, R2>::value; // C++17 |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 75 | template <class R1, class R2> inline constexpr bool ratio_less_equal_v |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 76 | = ratio_less_equal<R1, R2>::value; // C++17 |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 77 | template <class R1, class R2> inline constexpr bool ratio_greater_v |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 78 | = ratio_greater<R1, R2>::value; // C++17 |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 79 | template <class R1, class R2> inline constexpr bool ratio_greater_equal_v |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 80 | = ratio_greater_equal<R1, R2>::value; // C++17 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 81 | } |
| 82 | */ |
| 83 | |
Nikolas Klauser | b9a2658 | 2024-12-21 12:01:48 | [diff] [blame] | 84 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 85 | # include <__cxx03/ratio> |
| 86 | #else |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 87 | # include <__config> |
| 88 | # include <__type_traits/integral_constant.h> |
| 89 | # include <climits> |
| 90 | # include <cstdint> |
| 91 | # include <version> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 92 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 93 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 94 | # pragma GCC system_header |
| 95 | # endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 96 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 97 | _LIBCPP_PUSH_MACROS |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 98 | # include <__undef_macros> |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 99 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 100 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 101 | |
| 102 | // __static_gcd |
| 103 | |
| 104 | template <intmax_t _Xp, intmax_t _Yp> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 105 | inline const intmax_t __static_gcd = __static_gcd<_Yp, _Xp % _Yp>; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 106 | |
| 107 | template <intmax_t _Xp> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 108 | inline const intmax_t __static_gcd<_Xp, 0> = _Xp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 109 | |
Howard Hinnant | 05e4858 | 2011-11-01 23:13:37 | [diff] [blame] | 110 | template <> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 111 | inline const intmax_t __static_gcd<0, 0> = 1; |
Howard Hinnant | 05e4858 | 2011-11-01 23:13:37 | [diff] [blame] | 112 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 113 | // __static_lcm |
| 114 | |
| 115 | template <intmax_t _Xp, intmax_t _Yp> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 116 | inline const intmax_t __static_lcm = _Xp / __static_gcd<_Xp, _Yp> * _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 117 | |
| 118 | template <intmax_t _Xp> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 119 | inline const intmax_t __static_abs = _Xp < 0 ? -_Xp : _Xp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 120 | |
| 121 | template <intmax_t _Xp> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 122 | inline const intmax_t __static_sign = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 123 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 124 | template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> > |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 125 | class __ll_add; |
| 126 | |
| 127 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 131 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 132 | static_assert(_Xp <= max - _Yp, "overflow in __ll_add"); |
| 133 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 134 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 135 | static const intmax_t value = _Xp + _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 139 | class __ll_add<_Xp, _Yp, 0> { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 140 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 141 | static const intmax_t value = _Xp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 148 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 149 | static_assert(min - _Yp <= _Xp, "overflow in __ll_add"); |
| 150 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 151 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 152 | static const intmax_t value = _Xp + _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 153 | }; |
| 154 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 155 | template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> > |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 156 | class __ll_sub; |
| 157 | |
| 158 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 162 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 163 | static_assert(min + _Yp <= _Xp, "overflow in __ll_sub"); |
| 164 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 165 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 166 | static const intmax_t value = _Xp - _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 170 | class __ll_sub<_Xp, _Yp, 0> { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 171 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 172 | static const intmax_t value = _Xp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 179 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 180 | static_assert(_Xp <= max + _Yp, "overflow in __ll_sub"); |
| 181 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 182 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 183 | static const intmax_t value = _Xp - _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 191 | static const intmax_t __a_x = __static_abs<_Xp>; |
| 192 | static const intmax_t __a_y = __static_abs<_Yp>; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 193 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 194 | static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul"); |
| 195 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 196 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 197 | static const intmax_t value = _Xp * _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | template <intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 201 | class __ll_mul<0, _Yp> { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 202 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 203 | static const intmax_t value = 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | template <intmax_t _Xp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 207 | class __ll_mul<_Xp, 0> { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 208 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 209 | static const intmax_t value = 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | template <> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 213 | class __ll_mul<0, 0> { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 214 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 215 | static const intmax_t value = 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | // Not actually used but left here in case needed in future maintenance |
| 219 | template <intmax_t _Xp, intmax_t _Yp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 224 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 225 | static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div"); |
| 226 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 227 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 228 | static const intmax_t value = _Xp / _Yp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | template <intmax_t _Num, intmax_t _Den = 1> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 232 | class ratio { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 233 | static_assert(__static_abs<_Num> >= 0, "ratio numerator is out of range"); |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 234 | static_assert(_Den != 0, "ratio divide by 0"); |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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>; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 240 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 241 | public: |
Nikolas Klauser | b69ddbc | 2024-11-13 10:57:16 | [diff] [blame] | 242 | static inline _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd; |
| 243 | static inline _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 244 | |
| 245 | typedef ratio<num, den> type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 246 | }; |
| 247 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 248 | template <class _Tp> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 249 | inline const bool __is_ratio_v = false; |
| 250 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 251 | template <intmax_t _Num, intmax_t _Den> |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 252 | inline const bool __is_ratio_v<ratio<_Num, _Den> > = true; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 253 | |
| 254 | typedef ratio<1LL, 1000000000000000000LL> atto; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 269 | typedef ratio<1000000000000000000LL, 1LL> exa; |
| 270 | |
| 271 | template <class _R1, class _R2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 272 | struct __ratio_multiply { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 273 | private: |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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>; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 276 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 279 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 280 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 283 | }; |
| 284 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 285 | # ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 286 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 287 | template <class _R1, class _R2> |
| 288 | using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type; |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 289 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 290 | # else // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 291 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 292 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 293 | struct ratio_multiply : public __ratio_multiply<_R1, _R2>::type {}; |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 294 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 295 | # endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 296 | |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 297 | template <class _R1, class _R2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 298 | struct __ratio_divide { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 299 | private: |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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>; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 302 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 305 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 306 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 309 | }; |
| 310 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 311 | # ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 312 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 313 | template <class _R1, class _R2> |
| 314 | using ratio_divide = typename __ratio_divide<_R1, _R2>::type; |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 315 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 316 | # else // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 317 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 318 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 319 | struct ratio_divide : public __ratio_divide<_R1, _R2>::type {}; |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 320 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 321 | # endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 322 | |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 323 | template <class _R1, class _R2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 324 | struct __ratio_add { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 325 | private: |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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>; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 328 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 331 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 332 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 338 | }; |
| 339 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 340 | # ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 341 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 342 | template <class _R1, class _R2> |
| 343 | using ratio_add = typename __ratio_add<_R1, _R2>::type; |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 344 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 345 | # else // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 346 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 347 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 348 | struct ratio_add : public __ratio_add<_R1, _R2>::type {}; |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 349 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 350 | # endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 351 | |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 352 | template <class _R1, class _R2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 353 | struct __ratio_subtract { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 354 | private: |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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>; |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 357 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 360 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 361 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 367 | }; |
| 368 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 369 | # ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 370 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 371 | template <class _R1, class _R2> |
| 372 | using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type; |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 373 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 374 | # else // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 375 | |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 376 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 377 | struct ratio_subtract : public __ratio_subtract<_R1, _R2>::type {}; |
Howard Hinnant | 0c6a0fe | 2010-11-24 17:05:06 | [diff] [blame] | 378 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 379 | # endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3c6708 | 2011-05-31 16:55:36 | [diff] [blame] | 380 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 381 | // ratio_equal |
| 382 | |
| 383 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 384 | struct ratio_equal : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 387 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 388 | |
| 389 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 390 | struct ratio_not_equal : _BoolConstant<!ratio_equal<_R1, _R2>::value> { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 393 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 394 | |
| 395 | // ratio_less |
| 396 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 406 | }; |
| 407 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 408 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 409 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0> { |
| 410 | static const bool value = false; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 411 | }; |
| 412 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 413 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 414 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2> { |
| 415 | static const bool value = !_Odd; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 416 | }; |
| 417 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 418 | template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 419 | struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0> { |
| 420 | static const bool value = _Odd; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 421 | }; |
| 422 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 426 | }; |
| 427 | |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 428 | template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>, intmax_t _S2 = __static_sign<_R2::num> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 429 | struct __ratio_less { |
| 430 | static const bool value = _S1 < _S2; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | template <class _R1, class _R2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 434 | struct __ratio_less<_R1, _R2, 1LL, 1LL> { |
| 435 | static const bool value = __ratio_less1<_R1, _R2>::value; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | template <class _R1, class _R2> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 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; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 441 | }; |
| 442 | |
| 443 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 444 | struct ratio_less : _BoolConstant<__ratio_less<_R1, _R2>::value> { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 447 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 448 | |
| 449 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 450 | struct ratio_less_equal : _BoolConstant<!ratio_less<_R2, _R1>::value> { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 453 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 454 | |
| 455 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 456 | struct ratio_greater : _BoolConstant<ratio_less<_R2, _R1>::value> { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 459 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 460 | |
| 461 | template <class _R1, class _R2> |
Nikolas Klauser | af9c04f | 2025-04-09 21:47:57 | [diff] [blame] | 462 | struct ratio_greater_equal : _BoolConstant<!ratio_less<_R1, _R2>::value> { |
Nikolas Klauser | e3c958a | 2024-11-12 14:15:18 | [diff] [blame] | 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"); |
Mark de Wever | fe0d277 | 2024-02-11 12:53:59 | [diff] [blame] | 465 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 466 | |
| 467 | template <class _R1, class _R2> |
Nikolas Klauser | f695852 | 2025-01-08 16:12:59 | [diff] [blame] | 468 | using __ratio_gcd _LIBCPP_NODEBUG = ratio<__static_gcd<_R1::num, _R2::num>, __static_lcm<_R1::den, _R2::den> >; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 469 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 470 | # if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 471 | template <class _R1, class _R2> |
Louis Dionne | cb793e1 | 2021-09-22 13:35:32 | [diff] [blame] | 472 | inline constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value; |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 473 | |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 474 | template <class _R1, class _R2> |
Louis Dionne | cb793e1 | 2021-09-22 13:35:32 | [diff] [blame] | 475 | inline constexpr bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value; |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 476 | |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 477 | template <class _R1, class _R2> |
Louis Dionne | cb793e1 | 2021-09-22 13:35:32 | [diff] [blame] | 478 | inline constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value; |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 479 | |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 480 | template <class _R1, class _R2> |
Louis Dionne | cb793e1 | 2021-09-22 13:35:32 | [diff] [blame] | 481 | inline constexpr bool ratio_less_equal_v = ratio_less_equal<_R1, _R2>::value; |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 482 | |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 483 | template <class _R1, class _R2> |
Louis Dionne | cb793e1 | 2021-09-22 13:35:32 | [diff] [blame] | 484 | inline constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value; |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 485 | |
Marshall Clow | 40a01d5 | 2018-01-02 17:17:01 | [diff] [blame] | 486 | template <class _R1, class _R2> |
Louis Dionne | cb793e1 | 2021-09-22 13:35:32 | [diff] [blame] | 487 | inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value; |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 488 | # endif |
Marshall Clow | 825a9ed | 2015-11-30 05:04:48 | [diff] [blame] | 489 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 490 | _LIBCPP_END_NAMESPACE_STD |
| 491 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 492 | _LIBCPP_POP_MACROS |
| 493 | |
Nikolas Klauser | c166a9c | 2024-12-10 15:02:12 | [diff] [blame] | 494 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 495 | # include <type_traits> |
| 496 | # endif |
Nikolas Klauser | b9a2658 | 2024-12-21 12:01:48 | [diff] [blame] | 497 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
Nikolas Klauser | dc21ce4 | 2023-01-15 18:53:49 | [diff] [blame] | 498 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 499 | #endif // _LIBCPP_RATIO |