libstdc++
std_abs.h
Go to the documentation of this file.
00001 // -*- C++ -*- C library enhancements header.
00002 
00003 // Copyright (C) 2016-2019 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 // 2735. std::abs(short), std::abs(signed char) and others should return int
00068 
00069 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
00070   inline _GLIBCXX_CONSTEXPR double
00071   abs(double __x)
00072   { return __builtin_fabs(__x); }
00073 
00074   inline _GLIBCXX_CONSTEXPR float
00075   abs(float __x)
00076   { return __builtin_fabsf(__x); }
00077 
00078   inline _GLIBCXX_CONSTEXPR long double
00079   abs(long double __x)
00080   { return __builtin_fabsl(__x); }
00081 #endif
00082 
00083 #if defined(__GLIBCXX_TYPE_INT_N_0)
00084   inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
00085   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
00086 #endif
00087 #if defined(__GLIBCXX_TYPE_INT_N_1)
00088   inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
00089   abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
00090 #endif
00091 #if defined(__GLIBCXX_TYPE_INT_N_2)
00092   inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
00093   abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
00094 #endif
00095 #if defined(__GLIBCXX_TYPE_INT_N_3)
00096   inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
00097   abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
00098 #endif
00099 
00100 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
00101   inline _GLIBCXX_CONSTEXPR
00102   __float128
00103   abs(__float128 __x)
00104   { return __x < 0 ? -__x : __x; }
00105 #endif
00106 
00107 _GLIBCXX_END_NAMESPACE_VERSION
00108 } // namespace
00109 } // extern "C"++"
00110 
00111 #endif // _GLIBCXX_BITS_STD_ABS_H