2
0
mirror of https://github.com/boostorg/math.git synced 2026-02-19 14:32:32 +00:00

Special functions, octonions, quaternions by Hubert Holin

[SVN r10404]
This commit is contained in:
Jens Maurer
2001-06-23 08:02:37 +00:00
commit f483d1189b
6 changed files with 5757 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,155 @@
// boost atanh.hpp header file
// (C) Copyright Hubert Holin 2001. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// See http://www.boost.org for updates, documentation, and revision history.
#ifndef BOOST_ATANH_HPP
#define BOOST_ATANH_HPP
#include <cmath>
#include <limits>
#include <string>
#include <stdexcept>
// This is the inverse of the hyperbolic tangent function.
namespace boost
{
// These are implementation details (for main fare see below)
namespace detail
{
template <
typename T,
bool InfinitySupported
>
struct atanh_helper1_t
{
static T get_pos_infinity()
{
return(+std::numeric_limits<T>::infinity());
}
static T get_neg_infinity()
{
return(-std::numeric_limits<T>::infinity());
}
}; // boost::detail::atanh_helper1_t
template<typename T>
struct atanh_helper1_t<T, false>
{
static T get_pos_infinity()
{
::std::string error_reporting("Argument to atanh is +1 (result: +Infinity)!");
::std::out_of_range bad_argument(error_reporting);
throw(bad_argument);
}
static T get_neg_infinity()
{
::std::string error_reporting("Argument to atanh is -1 (result: -Infinity)!");
::std::out_of_range bad_argument(error_reporting);
throw(bad_argument);
}
}; // boost::detail::atanh_helper1_t
template <
typename T,
bool QuietNanSupported
>
struct atanh_helper2_t
{
static T get_pos_NaN()
{
return(+std::numeric_limits<T>::quiet_NaN());
}
static T get_neg_NaN()
{
return(-std::numeric_limits<T>::quiet_NaN());
}
}; // boost::detail::atanh_helper2_t
template<typename T>
struct atanh_helper2_t<T, false>
{
static T get_pos_NaN()
{
::std::string error_reporting("Argument to atanh is strictly greater than +1!");
::std::domain_error bad_argument(error_reporting);
throw(bad_argument);
}
static T get_neg_NaN()
{
::std::string error_reporting("Argument to atanh is strictly smaller than -1!");
::std::domain_error bad_argument(error_reporting);
throw(bad_argument);
}
}; // boost::detail::atanh_helper2_t
} // boost::detail
// This is the main fare
template<typename T>
inline T atanh(const T x)
{
using ::std::abs;
using ::std::sqrt;
using ::std::numeric_limits;
typedef detail::atanh_helper1_t<T, std::numeric_limits<T>::has_infinity> helper1_type;
typedef detail::atanh_helper2_t<T, std::numeric_limits<T>::has_quiet_NaN> helper2_type;
static T const e0 = sqrt(numeric_limits<T>::epsilon());
T const one = static_cast<T>(1);
T const two = static_cast<T>(2);
if (x < -one)
{
return(helper2_type::get_neg_NaN());
}
else if (x == -one)
{
return(helper1_type::get_neg_infinity());
}
else if (x == +one)
{
return(helper1_type::get_pos_infinity());
}
else if (x > +one)
{
return(helper2_type::get_pos_NaN());
}
else if (abs(x) < e0)
{
return(x);
}
else // -one < x <= -e0 or +e0 <= x < +one
{
using ::std::log;
return(log( (one + x) / (one - x) ) / two);
}
}
}
#endif /* BOOST_ATANH_HPP */

View File

@@ -0,0 +1,102 @@
// boost sinc.hpp header file
// (C) Copyright Hubert Holin 2001. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// See http://www.boost.org for updates, documentation, and revision history.
#ifndef BOOST_SINC_HPP
#define BOOST_SINC_HPP
#include <cmath>
#include <limits>
#include <string>
#include <stdexcept>
// These are the the "Sinus Cardinal" functions.
namespace boost
{
// This is the "Sinus Cardinal" of index Pi.
template<typename T>
inline T sinc_pi(const T x)
{
using ::std::abs;
using ::std::sin;
using ::std::sqrt;
using ::std::numeric_limits;
static T const e1 = numeric_limits<T>::epsilon();
static T const e2 = sqrt(e1);
static T const e3 = sqrt(e2);
if (abs(x) > e3)
{
return(sin(x)/x);
}
else
{
T result = static_cast<T>(1);
if (abs(x) > e1)
{
T x2 = x*x;
result -= x2/static_cast<T>(6);
if (abs(x) > e2)
{
result += (x2*x2)/static_cast<T>(120);
}
}
return(result);
}
}
template<typename T, template<typename> class U>
inline U<T> sinc_pi(const U<T> x)
{
using ::std::abs;
using ::std::sin;
using ::std::sqrt;
using ::std::numeric_limits;
static T const e1 = numeric_limits<T>::epsilon();
static T const e2 = sqrt(e1);
static T const e3 = sqrt(e2);
if (abs(x) > e3)
{
return(sin(x)/x);
}
else
{
U<T> result = static_cast< U<T> >(1);
if (abs(x) > e1)
{
U<T> x2 = x*x;
result -= x2/static_cast<T>(6);
if (abs(x) > e2)
{
result += (x2*x2)/static_cast<T>(120);
}
}
return(result);
}
}
}
#endif /* BOOST_SINC_HPP */

View File

@@ -0,0 +1,102 @@
// boost sinhc.hpp header file
// (C) Copyright Hubert Holin 2001. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// See http://www.boost.org for updates, documentation, and revision history.
#ifndef BOOST_SINHC_HPP
#define BOOST_SINHC_HPP
#include <cmath>
#include <limits>
#include <string>
#include <stdexcept>
// These are the the "Hyperbolic Sinus Cardinal" functions.
namespace boost
{
// This is the "Hyperbolic Sinus Cardinal" of index Pi.
template<typename T>
inline T sinhc_pi(const T x)
{
using ::std::abs;
using ::std::sinh;
using ::std::sqrt;
using ::std::numeric_limits;
static T const e1 = numeric_limits<T>::epsilon();
static T const e2 = sqrt(e1);
static T const e3 = sqrt(e2);
if (abs(x) > e3)
{
return(sinh(x)/x);
}
else
{
T result = static_cast<T>(1);
if (abs(x) > e1)
{
T x2 = x*x;
result += x2/static_cast<T>(6);
if (abs(x) > e2)
{
result += (x2*x2)/static_cast<T>(120);
}
}
return(result);
}
}
template<typename T, template<typename> class U>
inline U<T> sinhc_pi(const U<T> x)
{
using ::std::abs;
using ::std::sinh;
using ::std::sqrt;
using ::std::numeric_limits;
static T const e1 = numeric_limits<T>::epsilon();
static T const e2 = sqrt(e1);
static T const e3 = sqrt(e2);
if (abs(x) > e3)
{
return(sinh(x)/x);
}
else
{
U<T> result = static_cast< U<T> >(1);
if (abs(x) > e1)
{
U<T> x2 = x*x;
result += x2/static_cast<T>(6);
if (abs(x) > e2)
{
result += (x2*x2)/static_cast<T>(120);
}
}
return(result);
}
}
}
#endif /* BOOST_SINHC_HPP */