// <numeric> -*- C++ -*-
// Copyright (C) 2001-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file include/numeric
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_NUMERIC
#define _GLIBCXX_NUMERIC 1
#pragma GCC system_header
#include <bits/c++config.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_numeric.h>
#include <ext/numeric_traits.h>
#ifdef _GLIBCXX_PARALLEL
# include <parallel/numeric>
#endif
/**
* @defgroup numerics Numerics
*
* Components for performing numeric operations. Includes support for
* for complex number types, random number generation, numeric
* (n-at-a-time) arrays, generalized numeric algorithms, and special
* math functions.
*/
#if __cplusplus >= 201402L
#include <type_traits>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace __detail
{
// std::abs is not constexpr, doesn't support unsigned integers,
// and std::abs(std::numeric_limits<T>::min()) is undefined.
template<typename _Up, typename _Tp>
constexpr _Up
__absu(_Tp __val)
{
static_assert(is_unsigned<_Up>::value, "result type must be unsigned");
static_assert(sizeof(_Up) >= sizeof(_Tp),
"result type must be at least as wide as the input type");
return __val < 0 ? -(_Up)__val : (_Up)__val;
}
template<typename _Up> void __absu(bool) = delete;
// GCD implementation
template<typename _Tp>
constexpr _Tp
__gcd(_Tp __m, _Tp __n)
{
static_assert(is_unsigned<_Tp>::value, "type must be unsigned");
return __m == 0 ? __n
: __n == 0 ? __m
: __detail::__gcd(__n, _Tp(__m % __n));
}
// LCM implementation
template<typename _Tp>
constexpr _Tp
__lcm(_Tp __m, _Tp __n)
{
return (__m != 0 && __n != 0)
? (__m / __detail::__gcd(__m, __n)) * __n
: 0;
}
} // namespace __detail
#if __cplusplus > 201402L
#define __cpp_lib_gcd_lcm 201606
// These were used in drafts of SD-6:
#define __cpp_lib_gcd 201606
#define __cpp_lib_lcm 201606
/// Greatest common divisor
template<typename _Mn, typename _Nn>
constexpr common_type_t<_Mn, _Nn>
gcd(_Mn __m, _Nn __n) noexcept
{
static_assert(is_integral_v<_Mn>, "std::gcd arguments must be integers");
static_assert(is_integral_v<_Nn>, "std::gcd arguments must be integers");
static_assert(_Mn(2) != _Mn(1), "std::gcd arguments must not be bool");
static_assert(_Nn(2) != _Nn(1), "std::gcd arguments must not be bool");
using _Up = make_unsigned_t<common_type_t<_Mn, _Nn>>;
return __detail::__gcd(__detail::__absu<_Up>(__m),
__detail::__absu<_Up>(__n));
}
/// Least common multiple
template<typename _Mn, typename _Nn>
constexpr common_type_t<_Mn, _Nn>
lcm(_Mn __m, _Nn __n) noexcept
{
static_assert(is_integral_v<_Mn>, "std::lcm arguments must be integers");
static_assert(is_integral_v<_Nn>, "std::lcm arguments must be integers");
static_assert(_Mn(2) == 2, "std::lcm arguments must not be bool");
static_assert(_Nn(2) == 2, "std::lcm arguments must not be bool");
using _Up = make_unsigned_t<common_type_t<_Mn, _Nn>>;
return __detail::__lcm(__detail::__absu<_Up>(__m),
__detail::__absu<_Up>(__n));
}
#endif // C++17
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // C++14
#endif /* _GLIBCXX_NUMERIC */
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| backward | Folder | 0755 |
|
|
| bits | Folder | 0755 |
|
|
| debug | Folder | 0755 |
|
|
| decimal | Folder | 0755 |
|
|
| experimental | Folder | 0755 |
|
|
| ext | Folder | 0755 |
|
|
| parallel | Folder | 0755 |
|
|
| profile | Folder | 0755 |
|
|
| tr1 | Folder | 0755 |
|
|
| tr2 | Folder | 0755 |
|
|
| x86_64-redhat-linux | Folder | 0755 |
|
|
| algorithm | File | 2.46 KB | 0644 |
|
| any | File | 18.17 KB | 0644 |
|
| array | File | 11.38 KB | 0644 |
|
| atomic | File | 40.09 KB | 0644 |
|
| bitset | File | 44.83 KB | 0644 |
|
| cassert | File | 1.61 KB | 0644 |
|
| ccomplex | File | 1.3 KB | 0644 |
|
| cctype | File | 2.35 KB | 0644 |
|
| cerrno | File | 1.73 KB | 0644 |
|
| cfenv | File | 2 KB | 0644 |
|
| cfloat | File | 1.84 KB | 0644 |
|
| charconv | File | 16.32 KB | 0644 |
|
| chrono | File | 29.17 KB | 0644 |
|
| cinttypes | File | 2.11 KB | 0644 |
|
| ciso646 | File | 1.43 KB | 0644 |
|
| climits | File | 1.87 KB | 0644 |
|
| clocale | File | 1.86 KB | 0644 |
|
| cmath | File | 47.01 KB | 0644 |
|
| codecvt | File | 5.22 KB | 0644 |
|
| complex | File | 53.26 KB | 0644 |
|
| complex.h | File | 1.56 KB | 0644 |
|
| condition_variable | File | 8.74 KB | 0644 |
|
| csetjmp | File | 1.9 KB | 0644 |
|
| csignal | File | 1.81 KB | 0644 |
|
| cstdalign | File | 1.37 KB | 0644 |
|
| cstdarg | File | 1.82 KB | 0644 |
|
| cstdbool | File | 1.37 KB | 0644 |
|
| cstddef | File | 6.29 KB | 0644 |
|
| cstdint | File | 2.12 KB | 0644 |
|
| cstdio | File | 4.33 KB | 0644 |
|
| cstdlib | File | 6.18 KB | 0644 |
|
| cstring | File | 3.05 KB | 0644 |
|
| ctgmath | File | 1.33 KB | 0644 |
|
| ctime | File | 2.08 KB | 0644 |
|
| cuchar | File | 2.16 KB | 0644 |
|
| cwchar | File | 6.36 KB | 0644 |
|
| cwctype | File | 2.73 KB | 0644 |
|
| cxxabi.h | File | 21.46 KB | 0644 |
|
| deque | File | 2.6 KB | 0644 |
|
| exception | File | 4.69 KB | 0644 |
|
| fenv.h | File | 1.97 KB | 0644 |
|
| filesystem | File | 1.4 KB | 0644 |
|
| forward_list | File | 1.54 KB | 0644 |
|
| fstream | File | 35.92 KB | 0644 |
|
| functional | File | 36.87 KB | 0644 |
|
| future | File | 49.49 KB | 0644 |
|
| initializer_list | File | 2.9 KB | 0644 |
|
| iomanip | File | 16.16 KB | 0644 |
|
| ios | File | 1.56 KB | 0644 |
|
| iosfwd | File | 6.76 KB | 0644 |
|
| iostream | File | 2.63 KB | 0644 |
|
| istream | File | 32.07 KB | 0644 |
|
| iterator | File | 2.58 KB | 0644 |
|
| limits | File | 67.56 KB | 0644 |
|
| list | File | 2.53 KB | 0644 |
|
| locale | File | 1.45 KB | 0644 |
|
| map | File | 2.5 KB | 0644 |
|
| math.h | File | 4.26 KB | 0644 |
|
| memory | File | 4.6 KB | 0644 |
|
| mutex | File | 17.8 KB | 0644 |
|
| new | File | 7.34 KB | 0644 |
|
| numeric | File | 5.32 KB | 0644 |
|
| optional | File | 42.93 KB | 0644 |
|
| ostream | File | 21.57 KB | 0644 |
|
| queue | File | 2.41 KB | 0644 |
|
| random | File | 1.65 KB | 0644 |
|
| ratio | File | 19.42 KB | 0644 |
|
| regex | File | 1.85 KB | 0644 |
|
| scoped_allocator | File | 15.84 KB | 0644 |
|
| set | File | 2.5 KB | 0644 |
|
| shared_mutex | File | 18.95 KB | 0644 |
|
| sstream | File | 26.24 KB | 0644 |
|
| stack | File | 2.33 KB | 0644 |
|
| stdexcept | File | 7.79 KB | 0644 |
|
| stdlib.h | File | 2.2 KB | 0644 |
|
| streambuf | File | 29.31 KB | 0644 |
|
| string | File | 1.89 KB | 0644 |
|
| string_view | File | 20.3 KB | 0644 |
|
| system_error | File | 11.25 KB | 0644 |
|
| tgmath.h | File | 1.33 KB | 0644 |
|
| thread | File | 10.27 KB | 0644 |
|
| tuple | File | 58.94 KB | 0644 |
|
| type_traits | File | 83.86 KB | 0644 |
|
| typeindex | File | 3.02 KB | 0644 |
|
| typeinfo | File | 7.51 KB | 0644 |
|
| unordered_map | File | 1.8 KB | 0644 |
|
| unordered_set | File | 1.8 KB | 0644 |
|
| utility | File | 12.01 KB | 0644 |
|
| valarray | File | 39.33 KB | 0644 |
|
| variant | File | 47.11 KB | 0644 |
|
| vector | File | 2.68 KB | 0644 |
|