From b43ec3d6f08ab6b3044a2514f9bb8a8f1a0eb31f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 22 Dec 2013 18:52:54 +0100 Subject: pcm/Traits: add MIN and MAX Move from PcmClamp(). --- src/pcm/PcmUtils.hxx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/pcm/PcmUtils.hxx') diff --git a/src/pcm/PcmUtils.hxx b/src/pcm/PcmUtils.hxx index 06b3acb4d..0ca5dd4ac 100644 --- a/src/pcm/PcmUtils.hxx +++ b/src/pcm/PcmUtils.hxx @@ -51,19 +51,16 @@ static inline typename Traits::value_type PcmClamp(typename Traits::long_type x) { typedef typename Traits::value_type T; - typedef typename Traits::long_type U; - constexpr U MIN_VALUE = -(U(1) << (Traits::BITS - 1)); - constexpr U MAX_VALUE = (U(1) << (Traits::BITS - 1)) - 1; typedef std::numeric_limits limits; - static_assert(MIN_VALUE >= limits::min(), "out of range"); - static_assert(MAX_VALUE <= limits::max(), "out of range"); + static_assert(Traits::MIN >= limits::min(), "out of range"); + static_assert(Traits::MAX <= limits::max(), "out of range"); - if (gcc_unlikely(x < MIN_VALUE)) - return T(MIN_VALUE); + if (gcc_unlikely(x < Traits::MIN)) + return T(Traits::MIN); - if (gcc_unlikely(x > MAX_VALUE)) - return T(MAX_VALUE); + if (gcc_unlikely(x > Traits::MAX)) + return T(Traits::MAX); return T(x); } -- cgit v1.2.3