From 4a0dbcb338d12269106a4a7861aebaef10239d8f Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 28 Jul 2014 12:24:57 +0200 Subject: [PATCH] Updated Basic.inl Fixed StringToNumber not working with lowercase numbers Moved functions order to be alphabetical Former-commit-id: ff58d17afe38c39527a6ae898bfeb7f3282b2142 --- include/Nazara/Math/Basic.hpp | 4 +- include/Nazara/Math/Basic.inl | 85 ++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/include/Nazara/Math/Basic.hpp b/include/Nazara/Math/Basic.hpp index c100da41c..a7c90e5a0 100644 --- a/include/Nazara/Math/Basic.hpp +++ b/include/Nazara/Math/Basic.hpp @@ -24,8 +24,6 @@ template T NzApproach(T value, T objective, T increment); template constexpr T NzClamp(T value, T min, T max); template constexpr T NzDegrees(T degrees); template constexpr T NzDegreeToRadian(T degrees); -template T NzMultiplyAdd(T x, T y, T z); -unsigned int NzIntegralPow(unsigned int base, unsigned int exponent); unsigned int NzGetNearestPowerOfTwo(unsigned int number); unsigned int NzGetNumberLength(signed char number); unsigned int NzGetNumberLength(unsigned char number); @@ -36,7 +34,9 @@ unsigned int NzGetNumberLength(unsigned long long number); unsigned int NzGetNumberLength(float number, nzUInt8 precision = NAZARA_CORE_DECIMAL_DIGITS); unsigned int NzGetNumberLength(double number, nzUInt8 precision = NAZARA_CORE_DECIMAL_DIGITS); unsigned int NzGetNumberLength(long double number, nzUInt8 precision = NAZARA_CORE_DECIMAL_DIGITS); +unsigned int NzIntegralPow(unsigned int base, unsigned int exponent); template T NzLerp(T from, T to, T2 interpolation); +template T NzMultiplyAdd(T x, T y, T z); template T NzNormalizeAngle(T angle); template bool NzNumberEquals(T a, T b, T maxDifference = std::numeric_limits::epsilon()); NzString NzNumberToString(long long number, nzUInt8 radix = 10); diff --git a/include/Nazara/Math/Basic.inl b/include/Nazara/Math/Basic.inl index a90c291d8..6fc2f7506 100644 --- a/include/Nazara/Math/Basic.inl +++ b/include/Nazara/Math/Basic.inl @@ -46,46 +46,6 @@ constexpr T NzDegreeToRadian(T degrees) return degrees * F(M_PI/180.0); } -template -T NzMultiplyAdd(T x, T y, T z) -{ - return x*y + z; -} - -#ifdef FP_FAST_FMAF -template<> -inline float NzMultiplyAdd(float x, float y, float z) -{ - return std::fmaf(x, y, z); -} -#endif - -#ifdef FP_FAST_FMA -template<> -inline double NzMultiplyAdd(double x, double y, double z) -{ - return std::fma(x, y, z); -} -#endif - -#ifdef FP_FAST_FMAL -template<> -inline long double NzMultiplyAdd(long double x, long double y, long double z) -{ - return std::fmal(x, y, z); -} -#endif - -inline unsigned int NzIntegralPow(unsigned int base, unsigned int exponent) -{ - ///TODO: Marquer comme constexpr en C++14 - unsigned int r = 1; - for (unsigned int i = 0; i < exponent; ++i) - r *= base; - - return r; -} - inline unsigned int NzGetNearestPowerOfTwo(unsigned int number) { ///TODO: Marquer comme constexpr en C++14 @@ -181,6 +141,16 @@ inline unsigned int NzGetNumberLength(long double number, nzUInt8 precision) return NzGetNumberLength(static_cast(number)) + precision + 1; // Plus un pour le point } +inline unsigned int NzIntegralPow(unsigned int base, unsigned int exponent) +{ + ///TODO: Marquer comme constexpr en C++14 + unsigned int r = 1; + for (unsigned int i = 0; i < exponent; ++i) + r *= base; + + return r; +} + template T NzLerp(T from, T to, T2 interpolation) { @@ -192,6 +162,36 @@ T NzLerp(T from, T to, T2 interpolation) return from + interpolation*(to - from); } +template +T NzMultiplyAdd(T x, T y, T z) +{ + return x*y + z; +} + +#ifdef FP_FAST_FMAF +template<> +inline float NzMultiplyAdd(float x, float y, float z) +{ + return std::fmaf(x, y, z); +} +#endif + +#ifdef FP_FAST_FMA +template<> +inline double NzMultiplyAdd(double x, double y, double z) +{ + return std::fma(x, y, z); +} +#endif + +#ifdef FP_FAST_FMAL +template<> +inline long double NzMultiplyAdd(long double x, long double y, long double z) +{ + return std::fmal(x, y, z); +} +#endif + template T NzNormalizeAngle(T angle) { @@ -298,12 +298,13 @@ inline long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok) } #endif + static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + str.Simplify(); if (radix > 10) - str.ToUpper(); + str = str.ToUpper(); bool negative = str.StartsWith('-'); - static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char* digit = &str[(negative) ? 1 : 0]; unsigned long long total = 0;