bounds.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
  2. // Use, modification, and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See library home page at http://www.boost.org/libs/numeric/conversion
  6. //
  7. // Contact the author at: fernando_cacciola@hotmail.com
  8. //
  9. #ifndef BOOST_NUMERIC_CONVERSION_BOUNDS_DETAIL_FLC_12NOV2002_HPP
  10. #define BOOST_NUMERIC_CONVERSION_BOUNDS_DETAIL_FLC_12NOV2002_HPP
  11. #include "boost/limits.hpp"
  12. #include "boost/config.hpp"
  13. #include "boost/mpl/if.hpp"
  14. namespace boost { namespace numeric { namespace boundsdetail
  15. {
  16. template<class N>
  17. class Integral
  18. {
  19. typedef std::numeric_limits<N> limits ;
  20. public :
  21. static N lowest () { return limits::min BOOST_PREVENT_MACRO_SUBSTITUTION (); }
  22. static N highest () { return limits::max BOOST_PREVENT_MACRO_SUBSTITUTION (); }
  23. static N smallest() { return static_cast<N>(1); }
  24. } ;
  25. template<class N>
  26. class Float
  27. {
  28. typedef std::numeric_limits<N> limits ;
  29. public :
  30. static N lowest () { return static_cast<N>(-limits::max BOOST_PREVENT_MACRO_SUBSTITUTION ()) ; }
  31. static N highest () { return limits::max BOOST_PREVENT_MACRO_SUBSTITUTION (); }
  32. static N smallest() { return limits::min BOOST_PREVENT_MACRO_SUBSTITUTION (); }
  33. } ;
  34. template<class N>
  35. struct get_impl
  36. {
  37. typedef mpl::bool_< ::std::numeric_limits<N>::is_integer > is_int ;
  38. typedef Integral<N> impl_int ;
  39. typedef Float <N> impl_float ;
  40. typedef typename mpl::if_<is_int,impl_int,impl_float>::type type ;
  41. } ;
  42. } } } // namespace boost::numeric::boundsdetail.
  43. #endif
  44. //
  45. ///////////////////////////////////////////////////////////////////////////////////////////////