1169691Skan// -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 2007 Free Software Foundation, Inc. 4169691Skan// 5169691Skan// This file is part of the GNU ISO C++ Library. This library is free 6169691Skan// software; you can redistribute it and/or modify it under the terms 7169691Skan// of the GNU General Public License as published by the Free Software 8169691Skan// Foundation; either version 2, or (at your option) any later 9169691Skan// version. 10169691Skan 11169691Skan// This library is distributed in the hope that it will be useful, but 12169691Skan// WITHOUT ANY WARRANTY; without even the implied warranty of 13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14169691Skan// General Public License for more details. 15169691Skan 16169691Skan// You should have received a copy of the GNU General Public License along 17169691Skan// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19169691Skan// USA. 20169691Skan 21169691Skan// As a special exception, you may use this file as part of a free 22169691Skan// software library without restriction. Specifically, if other files 23169691Skan// instantiate templates or use macros or inline functions from this 24169691Skan// file, or you compile this file and link it with other files to 25169691Skan// produce an executable, this file does not by itself cause the 26169691Skan// resulting executable to be covered by the GNU General Public 27169691Skan// License. This exception does not however invalidate any other 28169691Skan// reasons why the executable file might be covered by the GNU General 29169691Skan// Public License. 30169691Skan 31169691Skan/** @file ext/numeric_traits.h 32169691Skan * This file is a GNU extension to the Standard C++ Library. 33169691Skan */ 34169691Skan 35169691Skan#ifndef _EXT_NUMERIC_TRAITS 36169691Skan#define _EXT_NUMERIC_TRAITS 1 37169691Skan 38169691Skan#pragma GCC system_header 39169691Skan 40169691Skan#include <limits> 41169691Skan#include <bits/cpp_type_traits.h> 42169691Skan#include <ext/type_traits.h> 43169691Skan 44169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 45169691Skan 46169691Skan // Compile time constants for builtin types. 47169691Skan // Sadly std::numeric_limits member functions cannot be used for this. 48169691Skan#define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0) 49169691Skan#define __glibcxx_digits(_Tp) \ 50169691Skan (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp)) 51169691Skan 52169691Skan#define __glibcxx_min(_Tp) \ 53169691Skan (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0) 54169691Skan 55169691Skan#define __glibcxx_max(_Tp) \ 56169691Skan (__glibcxx_signed(_Tp) ? \ 57169691Skan (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0) 58169691Skan 59169691Skan template<typename _Value> 60169691Skan struct __numeric_traits_integer 61169691Skan { 62169691Skan // Only integers for initialization of member constant. 63169691Skan static const _Value __min = __glibcxx_min(_Value); 64169691Skan static const _Value __max = __glibcxx_max(_Value); 65169691Skan }; 66169691Skan 67169691Skan template<typename _Value> 68169691Skan const _Value __numeric_traits_integer<_Value>::__min; 69169691Skan 70169691Skan template<typename _Value> 71169691Skan const _Value __numeric_traits_integer<_Value>::__max; 72169691Skan 73169691Skan template<typename _Value> 74169691Skan struct __numeric_traits_floating 75169691Skan { 76169691Skan // Only floating point types. See N1822. 77169691Skan static const int __max_digits10 = 78169691Skan 2 + std::numeric_limits<_Value>::digits * 3010/10000; 79169691Skan }; 80169691Skan 81169691Skan template<typename _Value> 82169691Skan const int __numeric_traits_floating<_Value>::__max_digits10; 83169691Skan 84169691Skan template<typename _Value> 85169691Skan struct __numeric_traits 86169691Skan : public __conditional_type<std::__is_integer<_Value>::__value, 87169691Skan __numeric_traits_integer<_Value>, 88169691Skan __numeric_traits_floating<_Value> >::__type 89169691Skan { }; 90169691Skan 91169691Skan_GLIBCXX_END_NAMESPACE 92169691Skan 93169691Skan#undef __glibcxx_signed 94169691Skan#undef __glibcxx_min 95169691Skan#undef __glibcxx_max 96169691Skan#undef __glibcxx_digits 97169691Skan 98169691Skan#endif 99