Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11078 from Minty-Meeo/mapfloat-tweak
Use std::llround in MapFloat
  • Loading branch information
AdmiralCurtiss committed Sep 23, 2022
2 parents 79c5d1b + 73dfcc1 commit 75c5022
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
Expand Up @@ -206,19 +206,19 @@ class EmulatedController
static_assert(std::is_integral<T>(), "T is only sane for int types.");
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");

static_assert(std::numeric_limits<long>::min() <= std::numeric_limits<T>::min() &&
std::numeric_limits<long>::max() >= std::numeric_limits<T>::max(),
"long is not a superset of T. use of std::lround is not sane.");
static_assert(std::numeric_limits<long long>::min() <= std::numeric_limits<T>::min() &&
std::numeric_limits<long long>::max() >= std::numeric_limits<T>::max(),
"long long is not a superset of T. use of std::llround is not sane.");

// Here we round when converting from float to int.
// After applying our deadzone, resizing, and reshaping math
// we sometimes have a near-zero value which is slightly negative. (e.g. -0.0001)
// Casting would round down but rounding will yield our "zero_value".

if (input_value > 0)
return T(std::lround((pos_1_value - zero_value) * input_value + zero_value));
return T(std::llround((pos_1_value - zero_value) * input_value + zero_value));
else
return T(std::lround((zero_value - neg_1_value) * input_value + zero_value));
return T(std::llround((zero_value - neg_1_value) * input_value + zero_value));
}

protected:
Expand Down

0 comments on commit 75c5022

Please sign in to comment.