30 #ifndef _GLIBCXX_MAX_SIZE_TYPE_H
31 #define _GLIBCXX_MAX_SIZE_TYPE_H 1
33 #pragma GCC system_header
35 #if __cplusplus > 201703L && __cpp_lib_concepts
48 namespace std _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Tp>
53 struct numeric_limits;
62 __max_size_type() =
default;
64 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
66 __max_size_type(_Tp __i) noexcept
67 : _M_val(__i), _M_msb(__i < 0)
71 __max_size_type(
const __max_diff_type& __d) noexcept;
73 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
75 operator _Tp() const noexcept
79 operator bool() const noexcept
80 {
return _M_val != 0 || _M_msb != 0; }
82 constexpr __max_size_type
86 constexpr __max_size_type
87 operator~() const noexcept
88 {
return __max_size_type{~_M_val, !_M_msb}; }
90 constexpr __max_size_type
92 {
return operator~() + 1; }
94 constexpr __max_size_type&
96 {
return *
this += 1; }
98 constexpr __max_size_type
99 operator++(
int) noexcept
106 constexpr __max_size_type&
107 operator--() noexcept
108 {
return *
this -= 1; }
110 constexpr __max_size_type
111 operator--(
int) noexcept
118 constexpr __max_size_type&
119 operator+=(
const __max_size_type& __r) noexcept
121 const auto __sum = _M_val + __r._M_val;
122 const bool __overflow = (__sum < _M_val);
123 _M_msb = _M_msb ^ __r._M_msb ^ __overflow;
128 constexpr __max_size_type&
129 operator-=(
const __max_size_type& __r) noexcept
130 {
return *
this += -__r; }
132 constexpr __max_size_type&
133 operator*=(__max_size_type __r) noexcept
135 constexpr __max_size_type __threshold
136 = __rep(1) << (_S_rep_bits / 2 - 1);
137 if (_M_val < __threshold && __r < __threshold)
140 _M_val = _M_val * __r._M_val;
146 const bool __lsb = _M_val & 1;
147 const bool __rlsb = __r._M_val & 1;
150 _M_val = (2 * _M_val * __r._M_val
151 + _M_val * __rlsb + __r._M_val * __lsb);
153 *
this += __rlsb * __lsb;
159 constexpr __max_size_type&
160 operator/=(
const __max_size_type& __r) noexcept
162 __glibcxx_assert(__r != 0);
164 if (!_M_msb && !__r._M_msb) [[likely]]
165 _M_val /= __r._M_val;
166 else if (_M_msb && __r._M_msb)
168 _M_val = (_M_val >= __r._M_val);
171 else if (!_M_msb && __r._M_msb)
173 else if (_M_msb && !__r._M_msb)
179 const auto __orig = *
this;
181 _M_val /= __r._M_val;
183 if (__orig - *
this * __r >= __r)
189 constexpr __max_size_type&
190 operator%=(
const __max_size_type& __r) noexcept
192 if (!_M_msb && !__r._M_msb) [[likely]]
193 _M_val %= __r._M_val;
195 *
this -= (*
this / __r) * __r;
199 constexpr __max_size_type&
200 operator<<=(
const __max_size_type& __r) noexcept
202 __glibcxx_assert(__r <= _S_rep_bits);
205 _M_msb = (_M_val >> (_S_rep_bits - __r._M_val)) & 1;
207 if (__r._M_val == _S_rep_bits) [[unlikely]]
210 _M_val <<= __r._M_val;
215 constexpr __max_size_type&
216 operator>>=(
const __max_size_type& __r) noexcept
218 __glibcxx_assert(__r <= _S_rep_bits);
221 if (__r._M_val == _S_rep_bits) [[unlikely]]
224 _M_val >>= __r._M_val;
226 if (_M_msb) [[unlikely]]
228 _M_val |= __rep(1) << (_S_rep_bits - __r._M_val);
235 constexpr __max_size_type&
236 operator&=(
const __max_size_type& __r) noexcept
238 _M_val &= __r._M_val;
239 _M_msb &= __r._M_msb;
243 constexpr __max_size_type&
244 operator|=(
const __max_size_type& __r) noexcept
246 _M_val |= __r._M_val;
247 _M_msb |= __r._M_msb;
251 constexpr __max_size_type&
252 operator^=(
const __max_size_type& __r) noexcept
254 _M_val ^= __r._M_val;
255 _M_msb ^= __r._M_msb;
259 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
260 friend constexpr _Tp&
261 operator+=(_Tp& __a,
const __max_size_type& __b) noexcept
262 {
return (__a =
static_cast<_Tp
>(__a + __b)); }
264 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
265 friend constexpr _Tp&
266 operator-=(_Tp& __a,
const __max_size_type& __b) noexcept
267 {
return (__a =
static_cast<_Tp
>(__a - __b)); }
269 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
270 friend constexpr _Tp&
271 operator*=(_Tp& __a,
const __max_size_type& __b) noexcept
272 {
return (__a =
static_cast<_Tp
>(__a * __b)); }
274 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
275 friend constexpr _Tp&
276 operator/=(_Tp& __a,
const __max_size_type& __b) noexcept
277 {
return (__a =
static_cast<_Tp
>(__a / __b)); }
279 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
280 friend constexpr _Tp&
281 operator%=(_Tp& __a,
const __max_size_type& __b) noexcept
282 {
return (__a =
static_cast<_Tp
>(__a % __b)); }
284 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
285 friend constexpr _Tp&
286 operator&=(_Tp& __a,
const __max_size_type& __b) noexcept
287 {
return (__a =
static_cast<_Tp
>(__a & __b)); }
289 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
290 friend constexpr _Tp&
291 operator|=(_Tp& __a,
const __max_size_type& __b) noexcept
292 {
return (__a =
static_cast<_Tp
>(__a | __b)); }
294 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
295 friend constexpr _Tp&
296 operator^=(_Tp& __a,
const __max_size_type& __b) noexcept
297 {
return (__a =
static_cast<_Tp
>(__a ^ __b)); }
299 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
300 friend constexpr _Tp&
301 operator<<=(_Tp& __a,
const __max_size_type& __b) noexcept
302 {
return (__a =
static_cast<_Tp
>(__a << __b)); }
304 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
305 friend constexpr _Tp&
306 operator>>=(_Tp& __a,
const __max_size_type& __b) noexcept
307 {
return (__a =
static_cast<_Tp
>(__a >> __b)); }
309 friend constexpr __max_size_type
310 operator+(__max_size_type __l,
const __max_size_type& __r) noexcept
316 friend constexpr __max_size_type
317 operator-(__max_size_type __l,
const __max_size_type& __r) noexcept
323 friend constexpr __max_size_type
324 operator*(__max_size_type __l,
const __max_size_type& __r) noexcept
330 friend constexpr __max_size_type
331 operator/(__max_size_type __l,
const __max_size_type& __r) noexcept
337 friend constexpr __max_size_type
338 operator%(__max_size_type __l,
const __max_size_type& __r) noexcept
344 friend constexpr __max_size_type
345 operator<<(__max_size_type __l,
const __max_size_type& __r) noexcept
351 friend constexpr __max_size_type
352 operator>>(__max_size_type __l,
const __max_size_type& __r) noexcept
358 friend constexpr __max_size_type
359 operator&(__max_size_type __l,
const __max_size_type& __r) noexcept
365 friend constexpr __max_size_type
366 operator|(__max_size_type __l,
const __max_size_type& __r) noexcept
372 friend constexpr __max_size_type
373 operator^(__max_size_type __l,
const __max_size_type& __r) noexcept
379 friend constexpr
bool
380 operator==(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
381 {
return __l._M_val == __r._M_val && __l._M_msb == __r._M_msb; }
383 #if __cpp_lib_three_way_comparison
384 friend constexpr strong_ordering
385 operator<=>(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
387 if (__l._M_msb ^ __r._M_msb)
388 return __l._M_msb ? strong_ordering::greater : strong_ordering::less;
390 return __l._M_val <=> __r._M_val;
393 friend constexpr
bool
394 operator!=(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
395 {
return !(__l == __r); }
397 friend constexpr
bool
398 operator<(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
400 if (__l._M_msb == __r._M_msb)
401 return __l._M_val < __r._M_val;
406 friend constexpr
bool
407 operator>(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
408 {
return __r < __l; }
410 friend constexpr
bool
411 operator<=(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
412 {
return !(__l > __r); }
414 friend constexpr
bool
415 operator>=(
const __max_size_type& __l,
const __max_size_type& __r) noexcept
416 {
return __r <= __l; }
419 #if __SIZEOF_INT128__
421 using __rep =
unsigned __int128;
423 using __rep =
unsigned long long;
425 static constexpr
size_t _S_rep_bits =
sizeof(__rep) * __CHAR_BIT__;
428 unsigned _M_msb:1 = 0;
431 __max_size_type(__rep __val,
int __msb) noexcept
432 : _M_val(__val), _M_msb(__msb)
435 friend __max_diff_type;
440 class __max_diff_type
443 __max_diff_type() =
default;
445 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
447 __max_diff_type(_Tp __i) noexcept
452 __max_diff_type(
const __max_size_type& __d) noexcept
456 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
458 operator _Tp() const noexcept
459 {
return static_cast<_Tp
>(_M_rep); }
462 operator bool() const noexcept
463 {
return _M_rep != 0; }
465 constexpr __max_diff_type
469 constexpr __max_diff_type
471 {
return __max_diff_type(-_M_rep); }
473 constexpr __max_diff_type
474 operator~() const noexcept
475 {
return __max_diff_type(~_M_rep); }
477 constexpr __max_diff_type&
478 operator++() noexcept
479 {
return *
this += 1; }
481 constexpr __max_diff_type
482 operator++(
int) noexcept
489 constexpr __max_diff_type&
490 operator--() noexcept
491 {
return *
this -= 1; }
493 constexpr __max_diff_type
494 operator--(
int) noexcept
501 constexpr __max_diff_type&
502 operator+=(
const __max_diff_type& __r) noexcept
504 _M_rep += __r._M_rep;
508 constexpr __max_diff_type&
509 operator-=(
const __max_diff_type& __r) noexcept
511 _M_rep -= __r._M_rep;
515 constexpr __max_diff_type&
516 operator*=(
const __max_diff_type& __r) noexcept
518 _M_rep *= __r._M_rep;
522 constexpr __max_diff_type&
523 operator/=(
const __max_diff_type& __r) noexcept
525 __glibcxx_assert (__r != 0);
526 const bool __neg = *
this < 0;
527 const bool __rneg = __r < 0;
528 if (!__neg && !__rneg)
529 _M_rep = _M_rep / __r._M_rep;
530 else if (__neg && __rneg)
531 _M_rep = -_M_rep / -__r._M_rep;
532 else if (__neg && !__rneg)
533 _M_rep = -(-_M_rep / __r._M_rep);
535 _M_rep = -(_M_rep / -__r._M_rep);
539 constexpr __max_diff_type&
540 operator%=(
const __max_diff_type& __r) noexcept
542 __glibcxx_assert (__r != 0);
543 if (*
this >= 0 && __r > 0)
544 _M_rep %= __r._M_rep;
546 *
this -= (*
this / __r) * __r;
550 constexpr __max_diff_type&
551 operator<<=(
const __max_diff_type& __r) noexcept
553 _M_rep.operator<<=(__r._M_rep);
557 constexpr __max_diff_type&
558 operator>>=(
const __max_diff_type& __r) noexcept
561 const auto __msb = _M_rep._M_msb;
562 _M_rep >>= __r._M_rep;
563 _M_rep._M_msb |= __msb;
567 constexpr __max_diff_type&
568 operator&=(
const __max_diff_type& __r) noexcept
570 _M_rep &= __r._M_rep;
574 constexpr __max_diff_type&
575 operator|=(
const __max_diff_type& __r) noexcept
577 _M_rep |= __r._M_rep;
581 constexpr __max_diff_type&
582 operator^=(
const __max_diff_type& __r) noexcept
584 _M_rep ^= __r._M_rep;
588 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
589 friend constexpr _Tp&
590 operator+=(_Tp& __a,
const __max_diff_type& __b) noexcept
591 {
return (__a =
static_cast<_Tp
>(__a + __b)); }
593 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
594 friend constexpr _Tp&
595 operator-=(_Tp& __a,
const __max_diff_type& __b) noexcept
596 {
return (__a =
static_cast<_Tp
>(__a - __b)); }
598 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
599 friend constexpr _Tp&
600 operator*=(_Tp& __a,
const __max_diff_type& __b) noexcept
601 {
return (__a =
static_cast<_Tp
>(__a * __b)); }
603 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
604 friend constexpr _Tp&
605 operator/=(_Tp& __a,
const __max_diff_type& __b) noexcept
606 {
return (__a =
static_cast<_Tp
>(__a / __b)); }
608 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
609 friend constexpr _Tp&
610 operator%=(_Tp& __a,
const __max_diff_type& __b) noexcept
611 {
return (__a =
static_cast<_Tp
>(__a % __b)); }
613 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
614 friend constexpr _Tp&
615 operator&=(_Tp& __a,
const __max_diff_type& __b) noexcept
616 {
return (__a =
static_cast<_Tp
>(__a & __b)); }
618 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
619 friend constexpr _Tp&
620 operator|=(_Tp& __a,
const __max_diff_type& __b) noexcept
621 {
return (__a =
static_cast<_Tp
>(__a | __b)); }
623 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
624 friend constexpr _Tp&
625 operator^=(_Tp& __a,
const __max_diff_type& __b) noexcept
626 {
return (__a =
static_cast<_Tp
>(__a ^ __b)); }
628 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
629 friend constexpr _Tp&
630 operator<<=(_Tp& __a,
const __max_diff_type& __b) noexcept
631 {
return (__a =
static_cast<_Tp
>(__a << __b)); }
633 template<
typename _Tp> requires integral<_Tp> || __is_int128<_Tp>
634 friend constexpr _Tp&
635 operator>>=(_Tp& __a,
const __max_diff_type& __b) noexcept
636 {
return (__a =
static_cast<_Tp
>(__a >> __b)); }
638 friend constexpr __max_diff_type
639 operator+(__max_diff_type __l,
const __max_diff_type& __r) noexcept
645 friend constexpr __max_diff_type
646 operator-(__max_diff_type __l,
const __max_diff_type& __r) noexcept
652 friend constexpr __max_diff_type
653 operator*(__max_diff_type __l,
const __max_diff_type& __r) noexcept
659 friend constexpr __max_diff_type
660 operator/(__max_diff_type __l,
const __max_diff_type& __r) noexcept
666 friend constexpr __max_diff_type
667 operator%(__max_diff_type __l,
const __max_diff_type& __r) noexcept
673 friend constexpr __max_diff_type
674 operator<<(__max_diff_type __l,
const __max_diff_type& __r) noexcept
680 friend constexpr __max_diff_type
681 operator>>(__max_diff_type __l,
const __max_diff_type& __r) noexcept
687 friend constexpr __max_diff_type
688 operator&(__max_diff_type __l,
const __max_diff_type& __r) noexcept
694 friend constexpr __max_diff_type
695 operator|(__max_diff_type __l,
const __max_diff_type& __r) noexcept
701 friend constexpr __max_diff_type
702 operator^(__max_diff_type __l,
const __max_diff_type& __r) noexcept
708 friend constexpr
bool
709 operator==(
const __max_diff_type& __l,
const __max_diff_type& __r) noexcept
710 {
return __l._M_rep == __r._M_rep; }
712 #if __cpp_lib_three_way_comparison
713 constexpr strong_ordering
714 operator<=>(
const __max_diff_type& __r)
const noexcept
716 const auto __lsign = _M_rep._M_msb;
717 const auto __rsign = __r._M_rep._M_msb;
718 if (__lsign ^ __rsign)
719 return __lsign ? strong_ordering::less : strong_ordering::greater;
721 return _M_rep <=> __r._M_rep;
724 friend constexpr
bool
725 operator!=(
const __max_diff_type& __l,
const __max_diff_type& __r) noexcept
726 {
return !(__l == __r); }
729 operator<(
const __max_diff_type& __r)
const noexcept
731 const auto __lsign = _M_rep._M_msb;
732 const auto __rsign = __r._M_rep._M_msb;
733 if (__lsign ^ __rsign)
736 return _M_rep < __r._M_rep;
739 friend constexpr
bool
740 operator>(
const __max_diff_type& __l,
const __max_diff_type& __r) noexcept
741 {
return __r < __l; }
743 friend constexpr
bool
744 operator<=(
const __max_diff_type& __l,
const __max_diff_type& __r) noexcept
745 {
return !(__r < __l); }
747 friend constexpr
bool
748 operator>=(
const __max_diff_type& __l,
const __max_diff_type& __r) noexcept
749 {
return !(__l < __r); }
753 __max_size_type _M_rep = 0;
755 friend class __max_size_type;
759 __max_size_type::__max_size_type(
const __max_diff_type& __d) noexcept
760 : __max_size_type(__d._M_rep)
767 struct numeric_limits<ranges::__detail::__max_size_type>
769 using _Sp = ranges::__detail::__max_size_type;
773 static constexpr
bool is_exact =
true;
774 static constexpr
int digits
777 =
static_cast<int>(
digits * numbers::ln2 / numbers::ln10);
785 {
return _Sp(
static_cast<_Sp::__rep
>(-1), 1); }
793 struct numeric_limits<ranges::__detail::__max_diff_type>
795 using _Dp = ranges::__detail::__max_diff_type;
796 using _Sp = ranges::__detail::__max_size_type;
800 static constexpr
bool is_exact =
true;
803 =
static_cast<int>(
digits * numbers::ln2 / numbers::ln10);
807 {
return _Dp(_Sp(0, 1)); }
811 {
return _Dp(_Sp(
static_cast<_Sp::__rep
>(-1), 0)); }
818 _GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
static constexpr bool is_integer
static constexpr int digits
static constexpr bool is_exact
static constexpr bool is_specialized
static constexpr bool is_signed
static constexpr int digits10
Properties of fundamental types.
static constexpr _Tp max() noexcept
static constexpr _Tp lowest() noexcept
static constexpr _Tp min() noexcept