libstdc++
|
00001 // -*- C++ -*- C library enhancements header. 00002 00003 // Copyright (C) 2016-2018 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/bits/std_abs.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{cmath, cstdlib} 00028 */ 00029 00030 #ifndef _GLIBCXX_BITS_STD_ABS_H 00031 #define _GLIBCXX_BITS_STD_ABS_H 00032 00033 #pragma GCC system_header 00034 00035 #include <bits/c++config.h> 00036 00037 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS 00038 #include_next <stdlib.h> 00039 #ifdef __CORRECT_ISO_CPP_MATH_H_PROTO 00040 # include_next <math.h> 00041 #endif 00042 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS 00043 00044 #undef abs 00045 00046 extern "C++" 00047 { 00048 namespace std _GLIBCXX_VISIBILITY(default) 00049 { 00050 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00051 00052 using ::abs; 00053 00054 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO 00055 inline long 00056 abs(long __i) { return __builtin_labs(__i); } 00057 #endif 00058 00059 #ifdef _GLIBCXX_USE_LONG_LONG 00060 inline long long 00061 abs(long long __x) { return __builtin_llabs (__x); } 00062 #endif 00063 00064 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00065 // 2192. Validity and return type of std::abs(0u) is unclear 00066 // 2294. <cstdlib> should declare abs(double) 00067 00068 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO 00069 inline _GLIBCXX_CONSTEXPR double 00070 abs(double __x) 00071 { return __builtin_fabs(__x); } 00072 00073 inline _GLIBCXX_CONSTEXPR float 00074 abs(float __x) 00075 { return __builtin_fabsf(__x); } 00076 00077 inline _GLIBCXX_CONSTEXPR long double 00078 abs(long double __x) 00079 { return __builtin_fabsl(__x); } 00080 #endif 00081 00082 #if defined(__GLIBCXX_TYPE_INT_N_0) 00083 inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0 00084 abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; } 00085 #endif 00086 #if defined(__GLIBCXX_TYPE_INT_N_1) 00087 inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1 00088 abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; } 00089 #endif 00090 #if defined(__GLIBCXX_TYPE_INT_N_2) 00091 inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2 00092 abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; } 00093 #endif 00094 #if defined(__GLIBCXX_TYPE_INT_N_3) 00095 inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3 00096 abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; } 00097 #endif 00098 00099 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) 00100 inline _GLIBCXX_CONSTEXPR 00101 __float128 00102 abs(__float128 __x) 00103 { return __x < 0 ? -__x : __x; } 00104 #endif 00105 00106 _GLIBCXX_END_NAMESPACE_VERSION 00107 } // namespace 00108 } 00109 00110 #endif // _GLIBCXX_BITS_STD_ABS_H