1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/numeric/interval/transc.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +/* Boost interval/transc.hpp template implementation file
1.5 + *
1.6 + * Copyright 2000 Jens Maurer
1.7 + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
1.8 + *
1.9 + * Distributed under the Boost Software License, Version 1.0.
1.10 + * (See accompanying file LICENSE_1_0.txt or
1.11 + * copy at http://www.boost.org/LICENSE_1_0.txt)
1.12 + */
1.13 +
1.14 +#ifndef BOOST_NUMERIC_INTERVAL_TRANSC_HPP
1.15 +#define BOOST_NUMERIC_INTERVAL_TRANSC_HPP
1.16 +
1.17 +#include <boost/config.hpp>
1.18 +#include <boost/numeric/interval/detail/interval_prototype.hpp>
1.19 +#include <boost/numeric/interval/detail/bugs.hpp>
1.20 +#include <boost/numeric/interval/detail/test_input.hpp>
1.21 +#include <boost/numeric/interval/rounding.hpp>
1.22 +#include <boost/numeric/interval/constants.hpp>
1.23 +#include <boost/numeric/interval/arith.hpp>
1.24 +#include <boost/numeric/interval/arith2.hpp>
1.25 +#include <algorithm>
1.26 +
1.27 +namespace boost {
1.28 +namespace numeric {
1.29 +
1.30 +template<class T, class Policies> inline
1.31 +interval<T, Policies> exp(const interval<T, Policies>& x)
1.32 +{
1.33 + typedef interval<T, Policies> I;
1.34 + if (interval_lib::detail::test_input(x))
1.35 + return I::empty();
1.36 + typename Policies::rounding rnd;
1.37 + return I(rnd.exp_down(x.lower()), rnd.exp_up(x.upper()), true);
1.38 +}
1.39 +
1.40 +template<class T, class Policies> inline
1.41 +interval<T, Policies> log(const interval<T, Policies>& x)
1.42 +{
1.43 + typedef interval<T, Policies> I;
1.44 + if (interval_lib::detail::test_input(x) ||
1.45 + !interval_lib::user::is_pos(x.upper()))
1.46 + return I::empty();
1.47 + typename Policies::rounding rnd;
1.48 + typedef typename Policies::checking checking;
1.49 + T l = !interval_lib::user::is_pos(x.lower())
1.50 + ? checking::neg_inf() : rnd.log_down(x.lower());
1.51 + return I(l, rnd.log_up(x.upper()), true);
1.52 +}
1.53 +
1.54 +template<class T, class Policies> inline
1.55 +interval<T, Policies> cos(const interval<T, Policies>& x)
1.56 +{
1.57 + if (interval_lib::detail::test_input(x))
1.58 + return interval<T, Policies>::empty();
1.59 + typename Policies::rounding rnd;
1.60 + typedef interval<T, Policies> I;
1.61 + typedef typename interval_lib::unprotect<I>::type R;
1.62 +
1.63 + // get lower bound within [0, pi]
1.64 + const R pi2 = interval_lib::pi_twice<R>();
1.65 + R tmp = fmod((const R&)x, pi2);
1.66 + if (width(tmp) >= pi2.lower())
1.67 + return I(static_cast<T>(-1), static_cast<T>(1), true); // we are covering a full period
1.68 + if (tmp.lower() >= interval_lib::constants::pi_upper<T>())
1.69 + return -cos(tmp - interval_lib::pi<R>());
1.70 + T l = tmp.lower();
1.71 + T u = tmp.upper();
1.72 +
1.73 + BOOST_USING_STD_MIN();
1.74 + // separate into monotone subintervals
1.75 + if (u <= interval_lib::constants::pi_lower<T>())
1.76 + return I(rnd.cos_down(u), rnd.cos_up(l), true);
1.77 + else if (u <= pi2.lower())
1.78 + return I(static_cast<T>(-1), rnd.cos_up(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.sub_down(pi2.lower(), u), l)), true);
1.79 + else
1.80 + return I(static_cast<T>(-1), static_cast<T>(1), true);
1.81 +}
1.82 +
1.83 +template<class T, class Policies> inline
1.84 +interval<T, Policies> sin(const interval<T, Policies>& x)
1.85 +{
1.86 + typedef interval<T, Policies> I;
1.87 + if (interval_lib::detail::test_input(x))
1.88 + return I::empty();
1.89 + typename Policies::rounding rnd;
1.90 + typedef typename interval_lib::unprotect<I>::type R;
1.91 + I r = cos((const R&)x - interval_lib::pi_half<R>());
1.92 + (void)&rnd;
1.93 + return r;
1.94 +}
1.95 +
1.96 +template<class T, class Policies> inline
1.97 +interval<T, Policies> tan(const interval<T, Policies>& x)
1.98 +{
1.99 + typedef interval<T, Policies> I;
1.100 + if (interval_lib::detail::test_input(x))
1.101 + return I::empty();
1.102 + typename Policies::rounding rnd;
1.103 + typedef typename interval_lib::unprotect<I>::type R;
1.104 +
1.105 + // get lower bound within [-pi/2, pi/2]
1.106 + const R pi = interval_lib::pi<R>();
1.107 + R tmp = fmod((const R&)x, pi);
1.108 + const T pi_half_d = interval_lib::constants::pi_half_lower<T>();
1.109 + if (tmp.lower() >= pi_half_d)
1.110 + tmp -= pi;
1.111 + if (tmp.lower() <= -pi_half_d || tmp.upper() >= pi_half_d)
1.112 + return I::whole();
1.113 + return I(rnd.tan_down(tmp.lower()), rnd.tan_up(tmp.upper()), true);
1.114 +}
1.115 +
1.116 +template<class T, class Policies> inline
1.117 +interval<T, Policies> asin(const interval<T, Policies>& x)
1.118 +{
1.119 + typedef interval<T, Policies> I;
1.120 + if (interval_lib::detail::test_input(x)
1.121 + || x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
1.122 + return I::empty();
1.123 + typename Policies::rounding rnd;
1.124 + T l = (x.lower() <= static_cast<T>(-1))
1.125 + ? -interval_lib::constants::pi_half_upper<T>()
1.126 + : rnd.asin_down(x.lower());
1.127 + T u = (x.upper() >= static_cast<T>(1) )
1.128 + ? interval_lib::constants::pi_half_upper<T>()
1.129 + : rnd.asin_up (x.upper());
1.130 + return I(l, u, true);
1.131 +}
1.132 +
1.133 +template<class T, class Policies> inline
1.134 +interval<T, Policies> acos(const interval<T, Policies>& x)
1.135 +{
1.136 + typedef interval<T, Policies> I;
1.137 + if (interval_lib::detail::test_input(x)
1.138 + || x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
1.139 + return I::empty();
1.140 + typename Policies::rounding rnd;
1.141 + T l = (x.upper() >= static_cast<T>(1) )
1.142 + ? static_cast<T>(0)
1.143 + : rnd.acos_down(x.upper());
1.144 + T u = (x.lower() <= static_cast<T>(-1))
1.145 + ? interval_lib::constants::pi_upper<T>()
1.146 + : rnd.acos_up (x.lower());
1.147 + return I(l, u, true);
1.148 +}
1.149 +
1.150 +template<class T, class Policies> inline
1.151 +interval<T, Policies> atan(const interval<T, Policies>& x)
1.152 +{
1.153 + typedef interval<T, Policies> I;
1.154 + if (interval_lib::detail::test_input(x))
1.155 + return I::empty();
1.156 + typename Policies::rounding rnd;
1.157 + return I(rnd.atan_down(x.lower()), rnd.atan_up(x.upper()), true);
1.158 +}
1.159 +
1.160 +template<class T, class Policies> inline
1.161 +interval<T, Policies> sinh(const interval<T, Policies>& x)
1.162 +{
1.163 + typedef interval<T, Policies> I;
1.164 + if (interval_lib::detail::test_input(x))
1.165 + return I::empty();
1.166 + typename Policies::rounding rnd;
1.167 + return I(rnd.sinh_down(x.lower()), rnd.sinh_up(x.upper()), true);
1.168 +}
1.169 +
1.170 +template<class T, class Policies> inline
1.171 +interval<T, Policies> cosh(const interval<T, Policies>& x)
1.172 +{
1.173 + typedef interval<T, Policies> I;
1.174 + if (interval_lib::detail::test_input(x))
1.175 + return I::empty();
1.176 + typename Policies::rounding rnd;
1.177 + if (interval_lib::user::is_neg(x.upper()))
1.178 + return I(rnd.cosh_down(x.upper()), rnd.cosh_up(x.lower()), true);
1.179 + else if (!interval_lib::user::is_neg(x.lower()))
1.180 + return I(rnd.cosh_down(x.lower()), rnd.cosh_up(x.upper()), true);
1.181 + else
1.182 + return I(static_cast<T>(0), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true);
1.183 +}
1.184 +
1.185 +template<class T, class Policies> inline
1.186 +interval<T, Policies> tanh(const interval<T, Policies>& x)
1.187 +{
1.188 + typedef interval<T, Policies> I;
1.189 + if (interval_lib::detail::test_input(x))
1.190 + return I::empty();
1.191 + typename Policies::rounding rnd;
1.192 + return I(rnd.tanh_down(x.lower()), rnd.tanh_up(x.upper()), true);
1.193 +}
1.194 +
1.195 +template<class T, class Policies> inline
1.196 +interval<T, Policies> asinh(const interval<T, Policies>& x)
1.197 +{
1.198 + typedef interval<T, Policies> I;
1.199 + if (interval_lib::detail::test_input(x))
1.200 + return I::empty();
1.201 + typename Policies::rounding rnd;
1.202 + return I(rnd.asinh_down(x.lower()), rnd.asinh_up(x.upper()), true);
1.203 +}
1.204 +
1.205 +template<class T, class Policies> inline
1.206 +interval<T, Policies> acosh(const interval<T, Policies>& x)
1.207 +{
1.208 + typedef interval<T, Policies> I;
1.209 + if (interval_lib::detail::test_input(x) || x.upper() < static_cast<T>(1))
1.210 + return I::empty();
1.211 + typename Policies::rounding rnd;
1.212 + T l = x.lower() <= static_cast<T>(1) ? static_cast<T>(0) : rnd.acosh_down(x.lower());
1.213 + return I(l, rnd.acosh_up(x.upper()), true);
1.214 +}
1.215 +
1.216 +template<class T, class Policies> inline
1.217 +interval<T, Policies> atanh(const interval<T, Policies>& x)
1.218 +{
1.219 + typedef interval<T, Policies> I;
1.220 + if (interval_lib::detail::test_input(x)
1.221 + || x.upper() < static_cast<T>(-1) || x.lower() > static_cast<T>(1))
1.222 + return I::empty();
1.223 + typename Policies::rounding rnd;
1.224 + typedef typename Policies::checking checking;
1.225 + T l = (x.lower() <= static_cast<T>(-1))
1.226 + ? checking::neg_inf() : rnd.atanh_down(x.lower());
1.227 + T u = (x.upper() >= static_cast<T>(1) )
1.228 + ? checking::pos_inf() : rnd.atanh_up (x.upper());
1.229 + return I(l, u, true);
1.230 +}
1.231 +
1.232 +} // namespace numeric
1.233 +} // namespace boost
1.234 +
1.235 +#endif // BOOST_NUMERIC_INTERVAL_TRANSC_HPP