<commit_before>#include "rosenbrock.h"

#include <qmath.h>

namespace
{
	Rosenbrock instance;
}

RpnOperand Rosenbrock::calculate(FunctionCalculator *calculator, QList<RpnOperand> actualArguments)
{
	m_calculator = calculator;

	m_functionName = actualArguments[0].value.value<QString>();

	m_sourcePoint = actualArguments[1].value.value<QList<Number> >();
	if (m_calculator->functionArguments(m_functionName).size() != m_sourcePoint.size()) {
		THROW(EWrongParametersCount(QObject::tr("Source point"), m_calculator->functionArguments(m_functionName).size()));
	}

	m_stopValue = actualArguments[2].value.value<Number>();
	m_accelerationStep = actualArguments[3].value.value<Number>();
	m_decreaseStep = actualArguments[4].value.value<Number>();

	m_steps = actualArguments[5].value.value<QList<Number> >();
	if (m_calculator->functionArguments(m_functionName).size() != m_steps.size()) {
		THROW(EWrongParametersCount(QObject::tr("Coordinate steps"), m_calculator->functionArguments(m_functionName).size()));
	}

	m_wrongStepsNumber = actualArguments[6].value.value<Number>();

	// Set start directions
	for (int i = 0; i < m_sourcePoint.size(); i++) {
		m_directions << QList<Number>();
		for (int k = 0; k < m_sourcePoint.size(); k++) {
			if (k == i) {
				m_directions[i] << 1;
			}
			else {
				m_directions[i] << 0;
			}
		}
	}


	RpnOperand result;
	result.type = RpnOperandVector;
	result.value = QVariant::fromValue(findMinimum());<commit_msg>Fix for crash on double using Rosenbrock method<commit_after>#include "rosenbrock.h"

#include <qmath.h>

namespace
{
	Rosenbrock instance;
}

RpnOperand Rosenbrock::calculate(FunctionCalculator *calculator, QList<RpnOperand> actualArguments)
{
	m_calculator = calculator;

	m_functionName = actualArguments[0].value.value<QString>();

	m_sourcePoint = actualArguments[1].value.value<QList<Number> >();
	if (m_calculator->functionArguments(m_functionName).size() != m_sourcePoint.size()) {
		THROW(EWrongParametersCount(QObject::tr("Source point"), m_calculator->functionArguments(m_functionName).size()));
	}

	m_stopValue = actualArguments[2].value.value<Number>();
	m_accelerationStep = actualArguments[3].value.value<Number>();
	m_decreaseStep = actualArguments[4].value.value<Number>();

	m_steps = actualArguments[5].value.value<QList<Number> >();
	if (m_calculator->functionArguments(m_functionName).size() != m_steps.size()) {
		THROW(EWrongParametersCount(QObject::tr("Coordinate steps"), m_calculator->functionArguments(m_functionName).size()));
	}

	m_wrongStepsNumber = actualArguments[6].value.value<Number>();

	// Set start directions
	m_directions.clear();
	for (int i = 0; i < m_sourcePoint.size(); i++) {
		m_directions << QList<Number>();
		for (int k = 0; k < m_sourcePoint.size(); k++) {
			if (k == i) {
				m_directions[i] << 1;
			}
			else {
				m_directions[i] << 0;
			}
		}
	}


	RpnOperand result;
	result.type = RpnOperandVector;
	result.value = QVariant::fromValue(findMinimum());
{'fraction_non_alphanumeric': 0.15986509274873525, 'fraction_numerical': 0.007419898819561552, 'mean_word_length': 6.146987951807229, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 35, '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': '621215', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1012, 'n_words': 153}