<commit_before>//----------------------------------------------------------------------------
//
// "Copyright Centre National d'Etudes Spatiales"
//
// License:  LGPL
//
// See LICENSE.txt file in the top level directory for more details.
//
//----------------------------------------------------------------------------
// $Id$

#include <otb/Equation.h>

namespace ossimplugins
{


const double Equation::Epsilon = 1.e-12;

Equation::Equation():
   _coefficients(NULL),
   _degree(0),
   _nbrSol(0),
   _solutions(NULL)
{
  _order.clear();
}

Equation::~Equation()
{
  if (_coefficients != NULL)
    delete [] _coefficients;
  if(_solutions != NULL)
    delete [] _solutions;
}

Equation::Equation(int degree, std::complex<double>* coefficients):
   _coefficients(NULL),
   _degree(0),
   _nbrSol(0),
   _solutions(NULL)
{
  _order.clear();
  CreateEquation(degree, coefficients);
}

void Equation::CreateEquation(int degree, std::complex<double>* coefficients)
{
  if (_coefficients != NULL)
  {
    delete [] _coefficients;
  }

  if(_order.size() != 0)
    _order.clear();
  if(_solutions != NULL)
    delete [] _solutions;

  _coefficients = new std::complex<double>[degree+1];
  _degree = degree;

  for (int i=0;i<=degree;i++)
  {
    _coefficients[i] = coefficients[i];
  }
}

Equation::Equation(const Equation& rhs)
{
  CreateEquation(rhs._degree, rhs._coefficients);
}

Equation& Equation::operator=(const Equation& rhs)
{
  CreateEquation(rhs._degree, rhs._coefficients);
  return *this;
}

void Equation::ComputeTrueDegree()
{
  double r = 0.0;
  _trueDegree = _degree +1;
  while (r <= Epsilon && _trueDegree > 0)
  {
    _trueDegree = _trueDegree - 1 ;
    r = abs(_coefficients[_trueDegree]);
  }
}

void Equation::Normalisation()
{
  for (int i=0;i<_trueDegree;i++)
  {
    _coefficients[i] = _coefficients[i] / _coefficients[_trueDegree];
  }
  _coefficients[_trueDegree] = std::complex<double>(1.0,0.0);

  int eMax = 0;
  int eMin = 0;
  int e;
  double r;

  /*
   * Normalisation by a power of 10
   */
  for (int i = 0 ; i < _trueDegree ; i++)
  {
    float rr = abs(_coefficients[i]) ;
    if (rr >= Epsilon)
    {
      rr = log10(rr) ;
      e = ((int)rr) / ((int)(_trueDegree - i)) ;
      if (e > eMax)
        eMax = e ;
      if (e < eMin)
        eMin = e ;
    }
  }

  /*
   * Normalisation for big values
   */
  if (eMax > 0)
  {
    /* Normalisation of the unknown for big values */
    _normalisationType = GreatValues;
    _normalisationCoefficient = pow (10.0, (float)eMax) ;
    r    = 1.0 ;
    for (int i = _trueDegree-1 ; i >= 0 ; i--)
    {
      r    = r * _normalisationCoefficient ;
      _coefficients[i] = _coefficients[i] /  std::complex<double>(r,0.0);
    }
  }
  else if (eMin < 0)
  {
    /* Normalisation of the unknown for small */
    _normalisationType = SmallValues;
    _normalisationCoefficient = pow(10.0,(float)(-eMin)) ;
    r    = 1.0 ;
    for (int i = _trueDegree-1 ; i >= 0 ; i--)
    {
      r    = r * _normalisationCoefficient ;
      _coefficients[i] = _coefficients[i] *  std::complex<double>(r,0.0);
    }
  }
}

void Equation::DeNormalisation()
{
  if (_normalisationType == GreatValues)
  {
    for (int i=0;i<_nbrSol;i++)
    {
      _solutions[i] = _solutions[i] * std::complex<double>(_normalisationCoefficient,0.0);
    }
  }
  else
  {
    for (int i=0;i<_nbrSol;i++)
    {
      _solutions[i] = _solutions[i] / std::complex<double>(_normalisationCoefficient,0.0);
    }
  }
}
std::complex<double> Equation::Proche(std::complex<double> z, double epsilon)
{
  double x, y, ax, ay ;<commit_msg>BUG: change in explicit cast.<commit_after>//----------------------------------------------------------------------------
//
// "Copyright Centre National d'Etudes Spatiales"
//
// License:  LGPL
//
// See LICENSE.txt file in the top level directory for more details.
//
//----------------------------------------------------------------------------
// $Id$

#include <otb/Equation.h>

namespace ossimplugins
{


const double Equation::Epsilon = 1.e-12;

Equation::Equation():
   _coefficients(NULL),
   _degree(0),
   _nbrSol(0),
   _solutions(NULL)
{
  _order.clear();
}

Equation::~Equation()
{
  if (_coefficients != NULL)
    delete [] _coefficients;
  if(_solutions != NULL)
    delete [] _solutions;
}

Equation::Equation(int degree, std::complex<double>* coefficients):
   _coefficients(NULL),
   _degree(0),
   _nbrSol(0),
   _solutions(NULL)
{
  _order.clear();
  CreateEquation(degree, coefficients);
}

void Equation::CreateEquation(int degree, std::complex<double>* coefficients)
{
  if (_coefficients != NULL)
  {
    delete [] _coefficients;
  }

  if(_order.size() != 0)
    _order.clear();
  if(_solutions != NULL)
    delete [] _solutions;

  _coefficients = new std::complex<double>[degree+1];
  _degree = degree;

  for (int i=0;i<=degree;i++)
  {
    _coefficients[i] = coefficients[i];
  }
}

Equation::Equation(const Equation& rhs)
{
  CreateEquation(rhs._degree, rhs._coefficients);
}

Equation& Equation::operator=(const Equation& rhs)
{
  CreateEquation(rhs._degree, rhs._coefficients);
  return *this;
}

void Equation::ComputeTrueDegree()
{
  double r = 0.0;
  _trueDegree = _degree +1;
  while (r <= Epsilon && _trueDegree > 0)
  {
    _trueDegree = _trueDegree - 1 ;
    r = abs(_coefficients[_trueDegree]);
  }
}

void Equation::Normalisation()
{
  for (int i=0;i<_trueDegree;i++)
  {
    _coefficients[i] = _coefficients[i] / _coefficients[_trueDegree];
  }
  _coefficients[_trueDegree] = std::complex<double>(1.0,0.0);

  int eMax = 0;
  int eMin = 0;
  int e;
  double r;

  /*
   * Normalisation by a power of 10
   */
  for (int i = 0 ; i < _trueDegree ; i++)
  {
    float rr = abs(_coefficients[i]) ;
    if (rr >= Epsilon)
    {
      rr = log10(rr) ;
      e = ((int)rr) / ((int)(_trueDegree - i)) ;
      if (e > eMax)
        eMax = e ;
      if (e < eMin)
        eMin = e ;
    }
  }

  /*
   * Normalisation for big values
   */
  if (eMax > 0)
  {
    /* Normalisation of the unknown for big values */
    _normalisationType = GreatValues;
    _normalisationCoefficient = pow (10.0, (double)eMax) ;
    r    = 1.0 ;
    for (int i = _trueDegree-1 ; i >= 0 ; i--)
    {
      r    = r * _normalisationCoefficient ;
      _coefficients[i] = _coefficients[i] /  std::complex<double>(r,0.0);
    }
  }
  else if (eMin < 0)
  {
    /* Normalisation of the unknown for small */
    _normalisationType = SmallValues;
    _normalisationCoefficient = pow(10.0,(double)(-eMin)) ;
    r    = 1.0 ;
    for (int i = _trueDegree-1 ; i >= 0 ; i--)
    {
      r    = r * _normalisationCoefficient ;
      _coefficients[i] = _coefficients[i] *  std::complex<double>(r,0.0);
    }
  }
}

void Equation::DeNormalisation()
{
  if (_normalisationType == GreatValues)
  {
    for (int i=0;i<_nbrSol;i++)
    {
      _solutions[i] = _solutions[i] * std::complex<double>(_normalisationCoefficient,0.0);
    }
  }
  else
  {
    for (int i=0;i<_nbrSol;i++)
    {
      _solutions[i] = _solutions[i] / std::complex<double>(_normalisationCoefficient,0.0);
    }
  }
}
std::complex<double> Equation::Proche(std::complex<double> z, double epsilon)
{
  double x, y, ax, ay ;
{'fraction_non_alphanumeric': 0.19285514931621547, 'fraction_numerical': 0.014792073681272676, 'mean_word_length': 2.565671641791045, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 37, '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': '818265', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2557, 'n_words': 524}