<commit_before>// Copyright (C) 2012 <NAME>
// This file is part of the "Nazara Engine - Mathematics module"
// For conditions of distribution and use, see copyright notice in Config.hpp

#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Config.hpp>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <Nazara/Core/Debug.hpp>

#define F(a) static_cast<T>(a)
#define F2(a) static_cast<T2>(a)

template<typename T>
T NzApproach(T value, T objective, T increment)
{
	if (value < objective)
		return std::min(value + increment, objective);
	else if (value > objective)
		return std::max(value - increment, objective);
	else
		return value;
}

template<typename T>
T NzClamp(T value, T min, T max)
{
	if (value < min)
		return min;
	else if (value > max)
		return max;
	else
		return value;
}

template<typename T>
T NzDegrees(T degrees)
{
	#if NAZARA_MATH_ANGLE_RADIAN
	return NzDegreeToRadian(degrees);
	#else
	return degrees;
	#endif
}

template<typename T>
T NzDegreeToRadian(T degrees)
{
	return degrees * F(M_PI/180.0);
}

unsigned int NzGetNumberLength(signed char number)
{
	// Le standard définit le char comme étant codé sur un octet
	static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");

	if (number >= 100)
		return 3;
	else if (number >= 10)
		return 2;
	else if (number >= 0)
		return 1;
	else if (number > -10)
		return 2;
	else if (number > -100)
		return 3;
	else
		return 4;
}

unsigned int NzGetNumberLength(unsigned char number)
{
	// Le standard définit le char comme étant codé sur un octet
	static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");

	if (number >= 100)
		return 3;
	else if (number >= 10)
		return 2;
	else
		return 1;
}

unsigned int NzGetNumberLength(int number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}

unsigned int NzGetNumberLength(unsigned int number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(number))+1;
}

unsigned int NzGetNumberLength(long long number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}

unsigned int NzGetNumberLength(unsigned long long number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(number))+1;
}

unsigned int NzGetNumberLength(float number, nzUInt8 precision)
{
	// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
	return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}

unsigned int NzGetNumberLength(double number, nzUInt8 precision)
{
	// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
	return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}

unsigned int NzGetNumberLength(long double number, nzUInt8 precision)
{
	// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
	return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}

template<typename T, typename T2>
T NzLerp(T from, T to, T2 interpolation)
{
	#ifdef NAZARA_DEBUG
	if (interpolation < F2(0.0) || interpolation > F2(1.0))
	{
		NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
		return F(0.0);
	}
	#endif

	return from + interpolation*(to - from);
}

template<typename T>
T NzNormalizeAngle(T angle)
{
	#if NAZARA_MATH_ANGLE_RADIAN
	const T limit = M_PI;
	#else
	const T limit = F(180.0);
	#endif

	///TODO: Trouver une solution sans duplication
	if (angle > F(0.0))
	{
		angle += limit;
		angle -= static_cast<int>(angle/(F(2.0)*limit))*(F(2.0)*limit);
		angle -= limit;
	}
	else
	{
		angle -= limit;
		angle -= static_cast<int>(angle/(F(2.0)*limit))*(F(2.0)*limit);
		angle += limit;
	}

	return angle;
}

template<typename T>
bool NzNumberEquals(T a, T b)
{
	return std::fabs(a-b) < std::numeric_limits<T>::epsilon();
}
<commit_msg>Cleaned NzNormalizeAngle code<commit_after>// Copyright (C) 2012 <NAME>
// This file is part of the "Nazara Engine - Mathematics module"
// For conditions of distribution and use, see copyright notice in Config.hpp

#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Config.hpp>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <Nazara/Core/Debug.hpp>

#define F(a) static_cast<T>(a)
#define F2(a) static_cast<T2>(a)

template<typename T>
T NzApproach(T value, T objective, T increment)
{
	if (value < objective)
		return std::min(value + increment, objective);
	else if (value > objective)
		return std::max(value - increment, objective);
	else
		return value;
}

template<typename T>
T NzClamp(T value, T min, T max)
{
	if (value < min)
		return min;
	else if (value > max)
		return max;
	else
		return value;
}

template<typename T>
T NzDegrees(T degrees)
{
	#if NAZARA_MATH_ANGLE_RADIAN
	return NzDegreeToRadian(degrees);
	#else
	return degrees;
	#endif
}

template<typename T>
T NzDegreeToRadian(T degrees)
{
	return degrees * F(M_PI/180.0);
}

unsigned int NzGetNumberLength(signed char number)
{
	// Le standard définit le char comme étant codé sur un octet
	static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");

	if (number >= 100)
		return 3;
	else if (number >= 10)
		return 2;
	else if (number >= 0)
		return 1;
	else if (number > -10)
		return 2;
	else if (number > -100)
		return 3;
	else
		return 4;
}

unsigned int NzGetNumberLength(unsigned char number)
{
	// Le standard définit le char comme étant codé sur un octet
	static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");

	if (number >= 100)
		return 3;
	else if (number >= 10)
		return 2;
	else
		return 1;
}

unsigned int NzGetNumberLength(int number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}

unsigned int NzGetNumberLength(unsigned int number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(number))+1;
}

unsigned int NzGetNumberLength(long long number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}

unsigned int NzGetNumberLength(unsigned long long number)
{
	if (number == 0)
		return 1;

	return static_cast<unsigned int>(std::log10(number))+1;
}

unsigned int NzGetNumberLength(float number, nzUInt8 precision)
{
	// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
	return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}

unsigned int NzGetNumberLength(double number, nzUInt8 precision)
{
	// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
	return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}

unsigned int NzGetNumberLength(long double number, nzUInt8 precision)
{
	// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
	return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}

template<typename T, typename T2>
T NzLerp(T from, T to, T2 interpolation)
{
	#ifdef NAZARA_DEBUG
	if (interpolation < F2(0.0) || interpolation > F2(1.0))
	{
		NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
		return F(0.0);
	}
	#endif

	return from + interpolation*(to - from);
}

template<typename T>
T NzNormalizeAngle(T angle)
{
	#if NAZARA_MATH_ANGLE_RADIAN
	const T limit = F(M_PI);
	#else
	const T limit = F(180.0);
	#endif

	///TODO: Trouver une solution sans duplication
	if (angle > F(0.0))
	{
		angle += limit;
		angle -= static_cast<int>(angle / (F(2.0)*limit)) * (F(2.0)*limit);
		angle -= limit;
	}
	else
	{
		angle -= limit;
		angle -= static_cast<int>(angle / (F(2.0)*limit)) * (F(2.0)*limit);
		angle += limit;
	}

	return angle;
}

template<typename T>
bool NzNumberEquals(T a, T b)
{
	return std::fabs(a-b) < std::numeric_limits<T>::epsilon();
}

{'fraction_non_alphanumeric': 0.13325077399380805, 'fraction_numerical': 0.029721362229102165, 'mean_word_length': 4.438383838383839, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 79, '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': '5874087', 'n_tokens_mistral': 3214, 'n_tokens_neox': 2977, 'n_words': 858}