<commit_before>//---------------------------------------------------------------------------
//      $Id$
//    Version: $Name$
//
//    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------


#include <deal.II/base/polynomial.h>
#include <deal.II/base/point.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/thread_management.h>

#include <cmath>

DEAL_II_NAMESPACE_OPEN



// have a lock that guarantees that at most one thread is changing and
// accessing the @p{coefficients} arrays of classes implementing
// polynomials with tables. make this lock local to this file.
//
// having only one lock for all of these classes is probably not going
// to be a problem since we only need it on very rare occasions. if
// someone finds this is a bottleneck, feel free to replace it by a
// more fine-grained solution
namespace
{
  Threads::ThreadMutex coefficients_lock;
}



namespace Polynomials
{

// -------------------- class Polynomial ---------------- //


  template <typename number>
  Polynomial<number>::Polynomial (const std::vector<number> &a)
                  :
		  coefficients             (a),
		  in_lagrange_product_form (false),
		  lagrange_weight          (1.)
  {}



  template <typename number>
  Polynomial<number>::Polynomial (const unsigned int n)
                  :
                  coefficients             (n+1, 0.),
		  in_lagrange_product_form (false),
		  lagrange_weight          (1.)
  {}



  template <typename number>
  Polynomial<number>::Polynomial (const std::vector<Point<1> > &supp,
				  const unsigned int            center)
                  :
                  in_lagrange_product_form (true)
  {
    Assert (supp.size()>0, ExcEmptyObject());
    AssertIndexRange (center, supp.size());

    lagrange_support_points.reserve (supp.size()-1);
    number tmp_lagrange_weight = 1.;
    for (unsigned int i=0; i<supp.size(); ++i)
      if (i!=center)
	{
	  lagrange_support_points.push_back(supp[i](0));
	  tmp_lagrange_weight *= supp[center](0) - supp[i](0);
	}

				// check for underflow and overflow
    Assert (std::fabs(tmp_lagrange_weight) > std::numeric_limits<number>::min(),
	    ExcMessage ("Underflow in computation of Lagrange denominator."));
    Assert (std::fabs(tmp_lagrange_weight) < std::numeric_limits<number>::max(),
	    ExcMessage ("Overflow in computation of Lagrange denominator."));
    lagrange_weight = 1./tmp_lagrange_weight;<commit_msg>Need to include limits.<commit_after>//---------------------------------------------------------------------------
//      $Id$
//    Version: $Name$
//
//    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------


#include <deal.II/base/polynomial.h>
#include <deal.II/base/point.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/thread_management.h>

#include <cmath>
#ifdef HAVE_STD_NUMERIC_LIMITS
#  include <limits>
#endif

DEAL_II_NAMESPACE_OPEN



// have a lock that guarantees that at most one thread is changing and
// accessing the @p{coefficients} arrays of classes implementing
// polynomials with tables. make this lock local to this file.
//
// having only one lock for all of these classes is probably not going
// to be a problem since we only need it on very rare occasions. if
// someone finds this is a bottleneck, feel free to replace it by a
// more fine-grained solution
namespace
{
  Threads::ThreadMutex coefficients_lock;
}



namespace Polynomials
{

// -------------------- class Polynomial ---------------- //


  template <typename number>
  Polynomial<number>::Polynomial (const std::vector<number> &a)
                  :
		  coefficients             (a),
		  in_lagrange_product_form (false),
		  lagrange_weight          (1.)
  {}



  template <typename number>
  Polynomial<number>::Polynomial (const unsigned int n)
                  :
                  coefficients             (n+1, 0.),
		  in_lagrange_product_form (false),
		  lagrange_weight          (1.)
  {}



  template <typename number>
  Polynomial<number>::Polynomial (const std::vector<Point<1> > &supp,
				  const unsigned int            center)
                  :
                  in_lagrange_product_form (true)
  {
    Assert (supp.size()>0, ExcEmptyObject());
    AssertIndexRange (center, supp.size());

    lagrange_support_points.reserve (supp.size()-1);
    number tmp_lagrange_weight = 1.;
    for (unsigned int i=0; i<supp.size(); ++i)
      if (i!=center)
	{
	  lagrange_support_points.push_back(supp[i](0));
	  tmp_lagrange_weight *= supp[center](0) - supp[i](0);
	}

				// check for underflow and overflow
#ifdef HAVE_STD_NUMERIC_LIMITS
    Assert (std::fabs(tmp_lagrange_weight) > std::numeric_limits<number>::min(),
	    ExcMessage ("Underflow in computation of Lagrange denominator."));
    Assert (std::fabs(tmp_lagrange_weight) < std::numeric_limits<number>::max(),
	    ExcMessage ("Overflow in computation of Lagrange denominator."));
#endif
    lagrange_weight = 1./tmp_lagrange_weight;
{'fraction_non_alphanumeric': 0.17251151257527453, 'fraction_numerical': 0.017357421183138506, 'mean_word_length': 2.3159130945390487, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5536951', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1589, 'n_words': 474}