mirror of
https://github.com/boostorg/numeric_conversion.git
synced 2026-07-21 13:33:43 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26ce13db68 | |||
| c1ec0bd06d | |||
| de96bf7a25 | |||
| 0f34dd8a66 |
Executable → Regular
@@ -13,6 +13,7 @@
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
|
||||
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -158,10 +159,17 @@ struct def_overflow_handler
|
||||
{
|
||||
void operator() ( range_check_result r ) // throw(negative_overflow,positive_overflow)
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
if ( r == cNegOverflow )
|
||||
throw negative_overflow() ;
|
||||
else if ( r == cPosOverflow )
|
||||
throw positive_overflow() ;
|
||||
#else
|
||||
if ( r == cNegOverflow )
|
||||
::boost::throw_exception(negative_overflow()) ;
|
||||
else if ( r == cPosOverflow )
|
||||
::boost::throw_exception(positive_overflow()) ;
|
||||
#endif
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
//
|
||||
//! Copyright (c) 2011
|
||||
//! Copyright (c) 2011-2012
|
||||
//! Brandon Kohn
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#if !defined(BOOST_NUMERIC_CONVERSION_DONT_USE_PREPROCESSED_FILES)
|
||||
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits.hpp>
|
||||
|
||||
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits_common.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_LONG_LONG)
|
||||
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits_long_long.hpp>
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if !BOOST_PP_IS_ITERATING
|
||||
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
#include <boost/preprocessor/seq/elem.hpp>
|
||||
#include <boost/preprocessor/seq/size.hpp>
|
||||
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
|
||||
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits.hpp")
|
||||
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits_common.hpp")
|
||||
#endif
|
||||
|
||||
//
|
||||
//! Copyright (c) 2011
|
||||
//! Copyright (c) 2011-2012
|
||||
//! Brandon Kohn
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -30,41 +36,29 @@
|
||||
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(preserve: 1)
|
||||
#endif
|
||||
|
||||
//! Generate the specializations for the built-in types.
|
||||
#if !defined( BOOST_NO_INT64_T )
|
||||
#define BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES() \
|
||||
(char) \
|
||||
(boost::int8_t) \
|
||||
(boost::uint8_t) \
|
||||
(boost::int16_t) \
|
||||
(boost::uint16_t) \
|
||||
(boost::int32_t) \
|
||||
(boost::uint32_t) \
|
||||
(boost::int64_t) \
|
||||
(boost::uint64_t) \
|
||||
(float) \
|
||||
(double) \
|
||||
(long double) \
|
||||
/***/
|
||||
#else
|
||||
#define BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES() \
|
||||
(char) \
|
||||
(boost::int8_t) \
|
||||
(boost::uint8_t) \
|
||||
(boost::int16_t) \
|
||||
(boost::uint16_t) \
|
||||
(boost::int32_t) \
|
||||
(boost::uint32_t) \
|
||||
(float) \
|
||||
(double) \
|
||||
(long double) \
|
||||
/***/
|
||||
#endif
|
||||
|
||||
//! These are the assumed common built in fundamental types (not typedefs/macros.)
|
||||
#define BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES() \
|
||||
(char) \
|
||||
(signed char) \
|
||||
(unsigned char) \
|
||||
(short) \
|
||||
(unsigned short) \
|
||||
(int) \
|
||||
(unsigned int) \
|
||||
(long) \
|
||||
(unsigned long) \
|
||||
(float) \
|
||||
(double) \
|
||||
(long double) \
|
||||
/***/
|
||||
|
||||
#define BOOST_NUMERIC_CONVERSION_SEQ_A() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()
|
||||
#define BOOST_NUMERIC_CONVERSION_SEQ_B() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_A())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
}}//namespace boost::numeric;
|
||||
@@ -72,14 +66,53 @@ namespace boost { namespace numeric {
|
||||
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(output: null)
|
||||
#endif
|
||||
|
||||
#if ( defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES) ) || !defined(BOOST_NO_LONG_LONG)
|
||||
|
||||
#undef BOOST_NUMERIC_CONVERSION_SEQ_A
|
||||
#undef BOOST_NUMERIC_CONVERSION_SEQ_B
|
||||
|
||||
#undef BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES
|
||||
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits_long_long.hpp")
|
||||
#endif
|
||||
|
||||
//
|
||||
//! Copyright (c) 2011-2012
|
||||
//! Brandon Kohn
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(preserve: 1)
|
||||
#endif
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
|
||||
#define BOOST_NUMERIC_CONVERSION_SEQ_A() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()(boost::long_long_type)(boost::ulong_long_type)
|
||||
#define BOOST_NUMERIC_CONVERSION_SEQ_B() (boost::long_long_type)(boost::ulong_long_type)
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_A())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
}}//namespace boost::numeric;
|
||||
|
||||
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(output: null)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#undef BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES
|
||||
#undef BOOST_NUMERIC_CONVERSION_SEQ_A
|
||||
#undef BOOST_NUMERIC_CONVERSION_SEQ_B
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_B())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
|
||||
//! Generate default traits for the specified source and target.
|
||||
@@ -89,13 +122,13 @@ namespace boost { namespace numeric {
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_A, BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES())
|
||||
, BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES())
|
||||
BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_A, BOOST_NUMERIC_CONVERSION_SEQ_A())
|
||||
, BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_SEQ_B())
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_BUILTIN_TYPES())> rounding_policy;
|
||||
typedef Trunc<BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_SEQ_B())> rounding_policy;
|
||||
};
|
||||
|
||||
#undef BOOST_NUMERIC_CONVERSION_A
|
||||
|
||||
+293
-303
File diff suppressed because it is too large
Load Diff
+347
@@ -0,0 +1,347 @@
|
||||
//
|
||||
//! Copyright (c) 2011-2012
|
||||
//! Brandon Kohn
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
namespace boost { namespace numeric {
|
||||
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
char
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
char
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
signed char
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
signed char
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned char
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned char
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
short
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
short
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned short
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned short
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
int
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
int
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned int
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned int
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
long
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
long
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned long
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
unsigned long
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
float
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
float
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
double
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
double
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
long double
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
long double
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
boost::long_long_type
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
boost::long_long_type
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
boost::ulong_long_type
|
||||
, boost::long_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::long_long_type> rounding_policy;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct numeric_cast_traits
|
||||
<
|
||||
boost::ulong_long_type
|
||||
, boost::ulong_long_type
|
||||
>
|
||||
{
|
||||
typedef def_overflow_handler overflow_policy;
|
||||
typedef UseInternalRangeChecker range_checking_policy;
|
||||
typedef Trunc<boost::ulong_long_type> rounding_policy;
|
||||
};
|
||||
}}
|
||||
Reference in New Issue
Block a user