OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc4/] [libstdc++-v3/] [include/] [tr1/] [beta_function.tcc] - Diff between revs 424 and 519

Only display areas with differences | Details | Blame | View Log

Rev 424 Rev 519
// Special functions -*- C++ -*-
// Special functions -*- C++ -*-
// Copyright (C) 2006, 2007, 2008, 2009
// Copyright (C) 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
// Free Software Foundation, Inc.
//
//
// This file is part of the GNU ISO C++ Library.  This library is free
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// any later version.
//
//
// This library is distributed in the hope that it will be useful,
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// GNU General Public License for more details.
//
//
// Under Section 7 of GPL version 3, you are granted additional
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// .
// .
/** @file tr1/beta_function.tcc
/** @file tr1/beta_function.tcc
 *  This is an internal header file, included by other library headers.
 *  This is an internal header file, included by other library headers.
 *  You should not attempt to use it directly.
 *  You should not attempt to use it directly.
 */
 */
//
//
// ISO C++ 14882 TR1: 5.2  Special functions
// ISO C++ 14882 TR1: 5.2  Special functions
//
//
// Written by Edward Smith-Rowland based on:
// Written by Edward Smith-Rowland based on:
//   (1) Handbook of Mathematical Functions,
//   (1) Handbook of Mathematical Functions,
//       ed. Milton Abramowitz and Irene A. Stegun,
//       ed. Milton Abramowitz and Irene A. Stegun,
//       Dover Publications,
//       Dover Publications,
//       Section 6, pp. 253-266
//       Section 6, pp. 253-266
//   (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl
//   (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl
//   (3) Numerical Recipes in C, by W. H. Press, S. A. Teukolsky,
//   (3) Numerical Recipes in C, by W. H. Press, S. A. Teukolsky,
//       W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992),
//       W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992),
//       2nd ed, pp. 213-216
//       2nd ed, pp. 213-216
//   (4) Gamma, Exploring Euler's Constant, Julian Havil,
//   (4) Gamma, Exploring Euler's Constant, Julian Havil,
//       Princeton, 2003.
//       Princeton, 2003.
#ifndef _GLIBCXX_TR1_BETA_FUNCTION_TCC
#ifndef _GLIBCXX_TR1_BETA_FUNCTION_TCC
#define _GLIBCXX_TR1_BETA_FUNCTION_TCC 1
#define _GLIBCXX_TR1_BETA_FUNCTION_TCC 1
namespace std
namespace std
{
{
namespace tr1
namespace tr1
{
{
  // [5.2] Special functions
  // [5.2] Special functions
  // Implementation-space details.
  // Implementation-space details.
  namespace __detail
  namespace __detail
  {
  {
    /**
    /**
     *   @brief  Return the beta function: \f$B(x,y)\f$.
     *   @brief  Return the beta function: \f$B(x,y)\f$.
     *
     *
     *   The beta function is defined by
     *   The beta function is defined by
     *   @f[
     *   @f[
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *   @f]
     *   @f]
     *
     *
     *   @param __x The first argument of the beta function.
     *   @param __x The first argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @return  The beta function.
     *   @return  The beta function.
     */
     */
    template
    template
    _Tp
    _Tp
    __beta_gamma(_Tp __x, _Tp __y)
    __beta_gamma(_Tp __x, _Tp __y)
    {
    {
      _Tp __bet;
      _Tp __bet;
#if _GLIBCXX_USE_C99_MATH_TR1
#if _GLIBCXX_USE_C99_MATH_TR1
      if (__x > __y)
      if (__x > __y)
        {
        {
          __bet = std::tr1::tgamma(__x)
          __bet = std::tr1::tgamma(__x)
                / std::tr1::tgamma(__x + __y);
                / std::tr1::tgamma(__x + __y);
          __bet *= std::tr1::tgamma(__y);
          __bet *= std::tr1::tgamma(__y);
        }
        }
      else
      else
        {
        {
          __bet = std::tr1::tgamma(__y)
          __bet = std::tr1::tgamma(__y)
                / std::tr1::tgamma(__x + __y);
                / std::tr1::tgamma(__x + __y);
          __bet *= std::tr1::tgamma(__x);
          __bet *= std::tr1::tgamma(__x);
        }
        }
#else
#else
      if (__x > __y)
      if (__x > __y)
        {
        {
          __bet = __gamma(__x) / __gamma(__x + __y);
          __bet = __gamma(__x) / __gamma(__x + __y);
          __bet *= __gamma(__y);
          __bet *= __gamma(__y);
        }
        }
      else
      else
        {
        {
          __bet = __gamma(__y) / __gamma(__x + __y);
          __bet = __gamma(__y) / __gamma(__x + __y);
          __bet *= __gamma(__x);
          __bet *= __gamma(__x);
        }
        }
#endif
#endif
      return __bet;
      return __bet;
    }
    }
    /**
    /**
     *   @brief  Return the beta function \f$B(x,y)\f$ using
     *   @brief  Return the beta function \f$B(x,y)\f$ using
     *           the log gamma functions.
     *           the log gamma functions.
     *
     *
     *   The beta function is defined by
     *   The beta function is defined by
     *   @f[
     *   @f[
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *   @f]
     *   @f]
     *
     *
     *   @param __x The first argument of the beta function.
     *   @param __x The first argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @return  The beta function.
     *   @return  The beta function.
     */
     */
    template
    template
    _Tp
    _Tp
    __beta_lgamma(_Tp __x, _Tp __y)
    __beta_lgamma(_Tp __x, _Tp __y)
    {
    {
#if _GLIBCXX_USE_C99_MATH_TR1
#if _GLIBCXX_USE_C99_MATH_TR1
      _Tp __bet = std::tr1::lgamma(__x)
      _Tp __bet = std::tr1::lgamma(__x)
                + std::tr1::lgamma(__y)
                + std::tr1::lgamma(__y)
                - std::tr1::lgamma(__x + __y);
                - std::tr1::lgamma(__x + __y);
#else
#else
      _Tp __bet = __log_gamma(__x)
      _Tp __bet = __log_gamma(__x)
                + __log_gamma(__y)
                + __log_gamma(__y)
                - __log_gamma(__x + __y);
                - __log_gamma(__x + __y);
#endif
#endif
      __bet = std::exp(__bet);
      __bet = std::exp(__bet);
      return __bet;
      return __bet;
    }
    }
    /**
    /**
     *   @brief  Return the beta function \f$B(x,y)\f$ using
     *   @brief  Return the beta function \f$B(x,y)\f$ using
     *           the product form.
     *           the product form.
     *
     *
     *   The beta function is defined by
     *   The beta function is defined by
     *   @f[
     *   @f[
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *   @f]
     *   @f]
     *
     *
     *   @param __x The first argument of the beta function.
     *   @param __x The first argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @return  The beta function.
     *   @return  The beta function.
     */
     */
    template
    template
    _Tp
    _Tp
    __beta_product(_Tp __x, _Tp __y)
    __beta_product(_Tp __x, _Tp __y)
    {
    {
      _Tp __bet = (__x + __y) / (__x * __y);
      _Tp __bet = (__x + __y) / (__x * __y);
      unsigned int __max_iter = 1000000;
      unsigned int __max_iter = 1000000;
      for (unsigned int __k = 1; __k < __max_iter; ++__k)
      for (unsigned int __k = 1; __k < __max_iter; ++__k)
        {
        {
          _Tp __term = (_Tp(1) + (__x + __y) / __k)
          _Tp __term = (_Tp(1) + (__x + __y) / __k)
                     / ((_Tp(1) + __x / __k) * (_Tp(1) + __y / __k));
                     / ((_Tp(1) + __x / __k) * (_Tp(1) + __y / __k));
          __bet *= __term;
          __bet *= __term;
        }
        }
      return __bet;
      return __bet;
    }
    }
    /**
    /**
     *   @brief  Return the beta function \f$ B(x,y) \f$.
     *   @brief  Return the beta function \f$ B(x,y) \f$.
     *
     *
     *   The beta function is defined by
     *   The beta function is defined by
     *   @f[
     *   @f[
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *     B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
     *   @f]
     *   @f]
     *
     *
     *   @param __x The first argument of the beta function.
     *   @param __x The first argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @param __y The second argument of the beta function.
     *   @return  The beta function.
     *   @return  The beta function.
     */
     */
    template
    template
    inline _Tp
    inline _Tp
    __beta(_Tp __x, _Tp __y)
    __beta(_Tp __x, _Tp __y)
    {
    {
      if (__isnan(__x) || __isnan(__y))
      if (__isnan(__x) || __isnan(__y))
        return std::numeric_limits<_Tp>::quiet_NaN();
        return std::numeric_limits<_Tp>::quiet_NaN();
      else
      else
        return __beta_lgamma(__x, __y);
        return __beta_lgamma(__x, __y);
    }
    }
  } // namespace std::tr1::__detail
  } // namespace std::tr1::__detail
}
}
}
}
#endif // __GLIBCXX_TR1_BETA_FUNCTION_TCC
#endif // __GLIBCXX_TR1_BETA_FUNCTION_TCC
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.