Added boost header

This commit is contained in:
Christophe Riccio
2012-01-08 01:26:07 +00:00
parent 9c3faaca40
commit c7d752cdf8
8946 changed files with 1732316 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
/* Boost interval/detail/alpha_rounding_control.hpp file
*
* Copyright 2005 Felix H<>fling, Guillaume Melquiond
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_ALPHA_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_ALPHA_ROUNDING_CONTROL_HPP
#if !defined(alpha) && !defined(__alpha__)
#error This header only works on Alpha CPUs.
#endif
#if defined(__GNUC__) || defined(__digital__) || defined(__DECCXX)
#include <float.h> // write_rnd() and read_rnd()
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#if defined(__GNUC__ )
typedef union {
::boost::long_long_type imode;
double dmode;
} rounding_mode_struct;
// set bits 59-58 (DYN),
// clear all exception bits and disable overflow (51) and inexact exceptions (62)
static const rounding_mode_struct mode_upward = { 0x4C08000000000000LL };
static const rounding_mode_struct mode_downward = { 0x4408000000000000LL };
static const rounding_mode_struct mode_to_nearest = { 0x4808000000000000LL };
static const rounding_mode_struct mode_toward_zero = { 0x4008000000000000LL };
struct alpha_rounding_control
{
typedef double rounding_mode;
static void set_rounding_mode(const rounding_mode mode)
{ __asm__ __volatile__ ("mt_fpcr %0" : : "f"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("mf_fpcr %0" : "=f"(mode)); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
};
#elif defined(__digital__) || defined(__DECCXX)
#if defined(__DECCXX) && !(defined(__FLT_ROUNDS) && __FLT_ROUNDS == -1)
#error Dynamic rounding mode not enabled. See cxx man page for details.
#endif
struct alpha_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode) { write_rnd(mode); }
static void get_rounding_mode(rounding_mode& mode) { mode = read_rnd(); }
static void downward() { set_rounding_mode(FP_RND_RM); }
static void upward() { set_rounding_mode(FP_RND_RP); }
static void to_nearest() { set_rounding_mode(FP_RND_RN); }
static void toward_zero() { set_rounding_mode(FP_RND_RZ); }
};
#endif
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
long double rintl(long double);
}
template<>
struct rounding_control<float>:
detail::alpha_rounding_control
{
static float force_rounding(const float r)
{ volatile float _r = r; return _r; }
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::alpha_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::alpha_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rintl(r); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_ALPHA_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,57 @@
/* Boost interval/detail/bcc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP
#ifndef __BORLANDC__
# error This header is only intended for Borland C++.
#endif
#ifndef _M_IX86
# error This header only works on x86 CPUs.
#endif
#include <float.h> // Borland C++ rounding control
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#ifndef BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
extern "C" { unsigned int _RTLENTRY _fm_init(void); }
struct borland_workaround {
borland_workaround() { _fm_init(); }
};
static borland_workaround borland_workaround_exec;
#endif // BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC
__inline double rint(double)
{ __emit__(0xD9); __emit__(0xFC); /* asm FRNDINT */ }
struct x86_rounding
{
typedef unsigned int rounding_mode;
static void get_rounding_mode(rounding_mode& mode)
{ mode = _control87(0, 0); }
static void set_rounding_mode(const rounding_mode mode)
{ _control87(mode, 0xffff); }
static double to_int(const double& x) { return rint(x); }
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,79 @@
/* Boost interval/detail/bugs.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BUGS
#define BOOST_NUMERIC_INTERVAL_DETAIL_BUGS
#include <boost/config.hpp>
#if defined(__GLIBC__) && (defined(__USE_MISC) || defined(__USE_XOPEN_EXTENDED) || defined(__USE_ISOC99)) && !defined(__ICC)
# define BOOST_HAS_INV_HYPERBOLIC
#endif
#ifdef BOOST_NO_STDC_NAMESPACE
# define BOOST_NUMERIC_INTERVAL_using_math(a) using ::a
# ifdef BOOST_HAS_INV_HYPERBOLIC
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
# endif
#else
# define BOOST_NUMERIC_INTERVAL_using_math(a) using std::a
# if defined(BOOST_HAS_INV_HYPERBOLIC)
# if defined(__GLIBCPP__) || defined(__GLIBCXX__)
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a
# else
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using std::a
# endif
# endif
#endif
#if defined(__COMO__) || defined(BOOST_INTEL)
# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#elif defined(BOOST_NO_STDC_NAMESPACE)
# define BOOST_NUMERIC_INTERVAL_using_max(a) using ::a
#else
# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a
#endif
#ifndef BOOST_NUMERIC_INTERVAL_using_ahyp
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
#endif
#if defined(__GNUC__) && (__GNUC__ <= 2)
// cf PR c++/1981 for a description of the bug
#include <algorithm>
#include <boost/config/no_tr1/cmath.hpp>
namespace boost {
namespace numeric {
using std::min;
using std::max;
using std::sqrt;
using std::exp;
using std::log;
using std::cos;
using std::tan;
using std::asin;
using std::acos;
using std::atan;
using std::ceil;
using std::floor;
using std::sinh;
using std::cosh;
using std::tanh;
# undef BOOST_NUMERIC_INTERVAL_using_max
# undef BOOST_NUMERIC_INTERVAL_using_math
# define BOOST_NUMERIC_INTERVAL_using_max(a)
# define BOOST_NUMERIC_INTERVAL_using_math(a)
# undef BOOST_NUMERIC_INTERVAL_using_ahyp
# define BOOST_NUMERIC_INTERVAL_using_ahyp(a)
} // namespace numeric
} // namespace boost
#endif
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_BUGS

View File

@@ -0,0 +1,50 @@
/* Boost interval/detail/c99_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP
#include <boost/numeric/interval/detail/c99sub_rounding_control.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
template<>
struct rounding_control<float>:
detail::c99_rounding_control
{
static float force_rounding(float const &r)
{ volatile float r_ = r; return r_; }
};
template<>
struct rounding_control<double>:
detail::c99_rounding_control
{
static double force_rounding(double const &r)
{ volatile double r_ = r; return r_; }
};
template<>
struct rounding_control<long double>:
detail::c99_rounding_control
{
static long double force_rounding(long double const &r)
{ volatile long double r_ = r; return r_; }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP

View File

@@ -0,0 +1,43 @@
/* Boost interval/detail/c99sub_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
#include <boost/detail/fenv.hpp> // ISO C 99 rounding mode control
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
extern "C" { double rint(double); }
struct c99_rounding_control
{
typedef int rounding_mode;
static void set_rounding_mode(rounding_mode mode) { fesetround(mode); }
static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
template<class T>
static T to_int(const T& r) { return rint(r); }
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP

View File

@@ -0,0 +1,194 @@
/* Boost interval/detail/division.hpp file
*
* Copyright 2003 Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
#include <boost/numeric/interval/detail/bugs.hpp>
#include <boost/numeric/interval/detail/test_input.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>
#include <algorithm>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(xu))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yl), rnd.div_up(xl, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yu), true);
else
return I(rnd.div_down(xl, yl), rnd.div_up(xu, yl), true);
else
if (::boost::numeric::interval_lib::user::is_neg(yu))
return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true);
else
return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const T& x, const interval<T, Policies>& y)
{
// assert(!in_zero(y));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& yl = y.lower();
const T& yu = y.upper();
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), rnd.div_up(x, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_positive(const interval<T, Policies>& x, const T& yu)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(checking::neg_inf(), rnd.div_up(xu, yu), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(rnd.div_down(xl, yu), checking::pos_inf(), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_positive(const T& x, const T& yu)
{
// assert(::boost::numeric::interval_lib::user::is_pos(yu));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(checking::neg_inf(), rnd.div_up(x, yu), true);
else
return I(rnd.div_down(x, yu), checking::pos_inf(), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_negative(const interval<T, Policies>& x, const T& yl)
{
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
return I(rnd.div_down(xu, yl), checking::pos_inf(), true);
else if (::boost::numeric::interval_lib::user::is_neg(xl))
return I(checking::neg_inf(), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(xl, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_negative(const T& x, const T& yl)
{
// assert(::boost::numeric::interval_lib::user::is_neg(yl));
typedef interval<T, Policies> I;
if (::boost::numeric::interval_lib::user::is_zero(x))
return I(static_cast<T>(0), static_cast<T>(0), true);
typename Policies::rounding rnd;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x))
return I(rnd.div_down(x, yl), checking::pos_inf(), true);
else
return I(checking::neg_inf(), rnd.div_up(x, yl), true);
}
template<class T, class Policies> inline
interval<T, Policies> div_zero(const interval<T, Policies>& x)
{
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) &&
::boost::numeric::interval_lib::user::is_zero(x.upper()))
return x;
else return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_zero(const T& x)
{
if (::boost::numeric::interval_lib::user::is_zero(x))
return interval<T, Policies>(static_cast<T>(0), static_cast<T>(0), true);
else return interval<T, Policies>::whole();
}
template<class T, class Policies> inline
interval<T, Policies> div_zero_part1(const interval<T, Policies>& x,
const interval<T, Policies>& y, bool& b)
{
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()));
if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && ::boost::numeric::interval_lib::user::is_zero(x.upper()))
{ b = false; return x; }
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
const T& xl = x.lower();
const T& xu = x.upper();
const T& yl = y.lower();
const T& yu = y.upper();
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(xu))
{ b = true; return I(checking::neg_inf(), rnd.div_up(xu, yu), true); }
else if (::boost::numeric::interval_lib::user::is_neg(xl))
{ b = false; return I(checking::neg_inf(), checking::pos_inf(), true); }
else
{ b = true; return I(checking::neg_inf(), rnd.div_up(xl, yl), true); }
}
template<class T, class Policies> inline
interval<T, Policies> div_zero_part2(const interval<T, Policies>& x,
const interval<T, Policies>& y)
{
// assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()) && (div_zero_part1(x, y, b), b));
typename Policies::rounding rnd;
typedef interval<T, Policies> I;
typedef typename Policies::checking checking;
if (::boost::numeric::interval_lib::user::is_neg(x.upper()))
return I(rnd.div_down(x.upper(), y.lower()), checking::pos_inf(), true);
else
return I(rnd.div_down(x.lower(), y.upper()), checking::pos_inf(), true);
}
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP

View File

@@ -0,0 +1,83 @@
/* Boost interval/detail/ia64_rounding_control.hpp file
*
* Copyright 2006-2007 Boris Gubenko
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP
#if !defined(ia64) && !defined(__ia64) && !defined(__ia64__)
#error This header only works on ia64 CPUs.
#endif
#if defined(__hpux)
# include <fenv.h>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
struct ia64_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode) {
fesetround(mode); }
static void get_rounding_mode(rounding_mode& mode) { mode = fegetround(); }
static void downward() { set_rounding_mode(FE_DOWNWARD); }
static void upward() { set_rounding_mode(FE_UPWARD); }
static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
};
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
long double rintl(long double);
}
template<>
struct rounding_control<float>:
detail::ia64_rounding_control
{
static float force_rounding(const float r)
{ volatile float _r = r; return _r; }
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::ia64_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::ia64_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rintl(r); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif /* __hpux */
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_IA64_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,41 @@
/* Boost interval/detail/interval_prototype.hpp file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP
namespace boost {
namespace numeric {
namespace interval_lib {
template<class T> struct rounded_math;
template<class T> struct checking_strict;
class comparison_error;
template<class Rounding, class Checking> struct policies;
/*
* default policies class
*/
template<class T>
struct default_policies
{
typedef policies<rounded_math<T>, checking_strict<T> > type;
};
} // namespace interval_lib
template<class T, class Policies = typename interval_lib::default_policies<T>::type >
class interval;
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP

View File

@@ -0,0 +1,100 @@
/* Boost interval/detail/msvc_rounding_control.hpp file
*
* Copyright 2000 Maarten Keijzer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP
#ifndef _MSC_VER
# error This header is only intended for MSVC, but might work for Borland as well
#endif
#include <float.h> // MSVC rounding control
// Although the function is called _control87, it seems to work for
// other FPUs too, so it does not have to be changed to _controlfp.
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#if BOOST_MSVC < 1400 || defined(WIN64)
extern "C" { double rint(double); }
#else
inline double rint(double x)
{
_asm FLD [x] ;
_asm FRNDINT ;
//_asm RET ;
}
#endif
struct x86_rounding
{
static unsigned int hard2msvc(unsigned short m) {
unsigned int n = 0;
if (m & 0x01) n |= _EM_INVALID;
if (m & 0x02) n |= _EM_DENORMAL;
if (m & 0x04) n |= _EM_ZERODIVIDE;
if (m & 0x08) n |= _EM_OVERFLOW;
if (m & 0x10) n |= _EM_UNDERFLOW;
if (m & 0x20) n |= _EM_INEXACT;
switch (m & 0x300) {
case 0x000: n |= _PC_24; break;
case 0x200: n |= _PC_53; break;
case 0x300: n |= _PC_64; break;
}
switch (m & 0xC00) {
case 0x000: n |= _RC_NEAR; break;
case 0x400: n |= _RC_DOWN; break;
case 0x800: n |= _RC_UP; break;
case 0xC00: n |= _RC_CHOP; break;
}
if (m & 0x1000) n |= _IC_AFFINE; // only useful on 287
return n;
}
static unsigned short msvc2hard(unsigned int n) {
unsigned short m = 0;
if (n & _EM_INVALID) m |= 0x01;
if (n & _EM_DENORMAL) m |= 0x02;
if (n & _EM_ZERODIVIDE) m |= 0x04;
if (n & _EM_OVERFLOW) m |= 0x08;
if (n & _EM_UNDERFLOW) m |= 0x10;
if (n & _EM_INEXACT) m |= 0x20;
switch (n & _MCW_RC) {
case _RC_NEAR: m |= 0x000; break;
case _RC_DOWN: m |= 0x400; break;
case _RC_UP: m |= 0x800; break;
case _RC_CHOP: m |= 0xC00; break;
}
switch (n & _MCW_PC) {
case _PC_24: m |= 0x000; break;
case _PC_53: m |= 0x200; break;
case _PC_64: m |= 0x300; break;
}
if ((n & _MCW_IC) == _IC_AFFINE) m |= 0x1000;
return m;
}
typedef unsigned short rounding_mode;
static void get_rounding_mode(rounding_mode& mode)
{ mode = msvc2hard(_control87(0, 0)); }
static void set_rounding_mode(const rounding_mode mode)
{ _control87(hard2msvc(mode), _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC); }
static double to_int(const double& x) { return rint(x); }
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,99 @@
/* Boost interval/detail/ppc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
* Copyright 2005 Guillaume Melquiond
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP
#if !defined(powerpc) && !defined(__powerpc__) && !defined(__ppc__)
#error This header only works on PPC CPUs.
#endif
#if defined(__GNUC__ ) || (__IBMCPP__ >= 700)
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
typedef union {
::boost::long_long_type imode;
double dmode;
} rounding_mode_struct;
static const rounding_mode_struct mode_upward = { 0xFFF8000000000002LL };
static const rounding_mode_struct mode_downward = { 0xFFF8000000000003LL };
static const rounding_mode_struct mode_to_nearest = { 0xFFF8000000000000LL };
static const rounding_mode_struct mode_toward_zero = { 0xFFF8000000000001LL };
struct ppc_rounding_control
{
typedef double rounding_mode;
static void set_rounding_mode(const rounding_mode mode)
{ __asm__ __volatile__ ("mtfsf 255,%0" : : "f"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("mffs %0" : "=f"(mode)); }
static void downward() { set_rounding_mode(mode_downward.dmode); }
static void upward() { set_rounding_mode(mode_upward.dmode); }
static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
};
} // namespace detail
// Do not declare the following C99 symbols if <math.h> provides them.
// Otherwise, conflicts may occur, due to differences between prototypes.
#if !defined(_ISOC99_SOURCE) && !defined(__USE_ISOC99)
extern "C" {
float rintf(float);
double rint(double);
}
#endif
template<>
struct rounding_control<float>:
detail::ppc_rounding_control
{
static float force_rounding(const float r)
{
float tmp;
__asm__ __volatile__ ("frsp %0, %1" : "=f" (tmp) : "f" (r));
return tmp;
}
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::ppc_rounding_control
{
static const double & force_rounding(const double& r) { return r; }
static double to_int(const double& r) { return rint(r); }
};
template<>
struct rounding_control<long double>:
detail::ppc_rounding_control
{
static const long double & force_rounding(const long double& r) { return r; }
static long double to_int(const long double& r) { return rint(r); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,112 @@
/* Boost interval/detail/sparc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*
* The basic code in this file was kindly provided by Jeremy Siek.
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
#if !defined(sparc) && !defined(__sparc__)
# error This header is only intended for SPARC CPUs.
#endif
#ifdef __SUNPRO_CC
# include <ieeefp.h>
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
struct sparc_rounding_control
{
typedef unsigned int rounding_mode;
static void set_rounding_mode(const rounding_mode& mode)
{
# if defined(__GNUC__)
__asm__ __volatile__("ld %0, %%fsr" : : "m"(mode));
# elif defined (__SUNPRO_CC)
fpsetround(fp_rnd(mode));
# elif defined(__KCC)
asm("sethi %hi(mode), %o1");
asm("ld [%o1+%lo(mode)], %fsr");
# else
# error Unsupported compiler for Sparc rounding control.
# endif
}
static void get_rounding_mode(rounding_mode& mode)
{
# if defined(__GNUC__)
__asm__ __volatile__("st %%fsr, %0" : "=m"(mode));
# elif defined (__SUNPRO_CC)
mode = fpgetround();
# elif defined(__KCC)
# error KCC on Sun SPARC get_round_mode: please fix me
asm("st %fsr, [mode]");
# else
# error Unsupported compiler for Sparc rounding control.
# endif
}
#if defined(__SUNPRO_CC)
static void downward() { set_rounding_mode(FP_RM); }
static void upward() { set_rounding_mode(FP_RP); }
static void to_nearest() { set_rounding_mode(FP_RN); }
static void toward_zero() { set_rounding_mode(FP_RZ); }
#else
static void downward() { set_rounding_mode(0xc0000000); }
static void upward() { set_rounding_mode(0x80000000); }
static void to_nearest() { set_rounding_mode(0x00000000); }
static void toward_zero() { set_rounding_mode(0x40000000); }
#endif
};
} // namespace detail
extern "C" {
float rintf(float);
double rint(double);
}
template<>
struct rounding_control<float>:
detail::sparc_rounding_control
{
static const float& force_rounding(const float& x) { return x; }
static float to_int(const float& x) { return rintf(x); }
};
template<>
struct rounding_control<double>:
detail::sparc_rounding_control
{
static const double& force_rounding(const double& x) { return x; }
static double to_int(const double& x) { return rint(x); }
};
template<>
struct rounding_control<long double>:
detail::sparc_rounding_control
{
static const long double& force_rounding(const long double& x) { return x; }
static long double to_int(const long double& x) { return rint(x); }
};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,76 @@
/* Boost interval/detail/test_input.hpp file
*
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP
#include <boost/numeric/interval/detail/interval_prototype.hpp>
namespace boost {
namespace numeric {
namespace interval_lib {
namespace user {
template<class T> inline
bool is_zero(T const &v) { return v == static_cast<T>(0); }
template<class T> inline
bool is_neg (T const &v) { return v < static_cast<T>(0); }
template<class T> inline
bool is_pos (T const &v) { return v > static_cast<T>(0); }
} // namespace user
namespace detail {
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x) {
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper());
}
template<class T, class Policies1, class Policies2> inline
bool test_input(const interval<T, Policies1>& x, const interval<T, Policies2>& y) {
typedef typename Policies1::checking checking1;
typedef typename Policies2::checking checking2;
return checking1::is_empty(x.lower(), x.upper()) ||
checking2::is_empty(y.lower(), y.upper());
}
template<class T, class Policies> inline
bool test_input(const T& x, const interval<T, Policies>& y) {
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper());
}
template<class T, class Policies> inline
bool test_input(const interval<T, Policies>& x, const T& y) {
typedef typename Policies::checking checking;
return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y);
}
template<class T, class Policies> inline
bool test_input(const T& x) {
typedef typename Policies::checking checking;
return checking::is_nan(x);
}
template<class T, class Policies> inline
bool test_input(const T& x, const T& y) {
typedef typename Policies::checking checking;
return checking::is_nan(x) || checking::is_nan(y);
}
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif // BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP

View File

@@ -0,0 +1,108 @@
/* Boost interval/detail/x86_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP
#ifdef __GNUC__
# include <boost/numeric/interval/detail/x86gcc_rounding_control.hpp>
#elif defined(__BORLANDC__)
# include <boost/numeric/interval/detail/bcc_rounding_control.hpp>
#elif defined(_MSC_VER)
# include <boost/numeric/interval/detail/msvc_rounding_control.hpp>
#elif defined(__MWERKS__) || defined(__ICC) || defined (__SUNPRO_CC)
# define BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
# include <boost/numeric/interval/detail/c99sub_rounding_control.hpp>
#else
# error Unsupported C++ compiler.
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
#ifdef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
typedef c99_rounding_control x86_rounding_control;
#undef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
#else
struct fpu_rounding_modes
{
unsigned short to_nearest;
unsigned short downward;
unsigned short upward;
unsigned short toward_zero;
};
// exceptions masked, extended precision
// hardware default is 0x037f (0x1000 only has a meaning on 287)
static const fpu_rounding_modes rnd_mode = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
struct x86_rounding_control: x86_rounding
{
static void to_nearest() { set_rounding_mode(rnd_mode.to_nearest); }
static void downward() { set_rounding_mode(rnd_mode.downward); }
static void upward() { set_rounding_mode(rnd_mode.upward); }
static void toward_zero() { set_rounding_mode(rnd_mode.toward_zero); }
};
#endif // BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM
} // namespace detail
template<>
struct rounding_control<float>: detail::x86_rounding_control
{
static float force_rounding(const float& r)
{ volatile float r_ = r; return r_; }
};
template<>
struct rounding_control<double>: detail::x86_rounding_control
{
/*static double force_rounding(double r)
{ asm volatile ("" : "+m"(r) : ); return r; }*/
static double force_rounding(const double& r)
{ volatile double r_ = r; return r_; }
};
namespace detail {
template<bool>
struct x86_rounding_control_long_double;
template<>
struct x86_rounding_control_long_double<false>: x86_rounding_control
{
static long double force_rounding(long double const &r)
{ volatile long double r_ = r; return r_; }
};
template<>
struct x86_rounding_control_long_double<true>: x86_rounding_control
{
static long double const &force_rounding(long double const &r)
{ return r; }
};
} // namespace detail
template<>
struct rounding_control<long double>:
detail::x86_rounding_control_long_double< (sizeof(long double) >= 10) >
{};
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP */

View File

@@ -0,0 +1,51 @@
/* Boost interval/detail/x86gcc_rounding_control.hpp file
*
* Copyright 2000 Jens Maurer
* Copyright 2002 Herv<72> Br<42>nnimann, Guillaume Melquiond, Sylvain Pion
*
* 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)
*/
#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
#define BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
#ifndef __GNUC__
# error This header only works with GNU CC.
#endif
#ifndef __i386__
# error This header only works on x86 CPUs.
#endif
namespace boost {
namespace numeric {
namespace interval_lib {
namespace detail {
struct x86_rounding
{
typedef unsigned short rounding_mode;
static void set_rounding_mode(const rounding_mode& mode)
{ __asm__ __volatile__ ("fldcw %0" : : "m"(mode)); }
static void get_rounding_mode(rounding_mode& mode)
{ __asm__ __volatile__ ("fnstcw %0" : "=m"(mode)); }
template<class T>
static T to_int(T r)
{
T r_;
__asm__ ("frndint" : "=&t"(r_) : "0"(r));
return r_;
}
};
} // namespace detail
} // namespace interval_lib
} // namespace numeric
} // namespace boost
#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP */