diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index 7391c25736..4b74aef324 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -184,6 +184,10 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
  • NEW: Added JKQTMathText::useGuiFonts()
  • NEW: Added JKQTMathText::setFontOptions(), which allows to make fonts initially e.g. bold, italic, ... and extended JKQTMathText::setFontSpecial() accordingly
  • +
  • JKQTPCommon:
  • JKQTFastPloter:
  • diff --git a/lib/jkqtcommon/jkqtpmathtools.h b/lib/jkqtcommon/jkqtpmathtools.h index e8309d56b9..7211a12cd0 100644 --- a/lib/jkqtcommon/jkqtpmathtools.h +++ b/lib/jkqtcommon/jkqtpmathtools.h @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef max # undef max @@ -233,7 +234,7 @@ inline T jkqtp_boundedRoundTo(const double& v) { return jkqtp_boundedRoundTo(std::numeric_limits::min(), v, std::numeric_limits::max()); } -/** \brief bounds a value \a v to the given range \a min ... \a max +/** \brief limits a value \a v to the given range \a min ... \a max * \ingroup jkqtptools_math_basic * * \tparam T a numeric datatype (int, double, ...) @@ -243,9 +244,25 @@ inline T jkqtp_boundedRoundTo(const double& v) { */ template inline T jkqtp_bounded(T min, T v, T max) { - if (vmax) return max; - return v; + return (vmax)? max : v); +} + +/** \brief limits a value \a v to the range of the given type \a T , i.e. \c std::numeric_limits::min() ... \c std::numeric_limits::max() + * \ingroup jkqtptools_math_basic + * + * \tparam T a numeric datatype (int, double, ...) for the output + * \tparam TIn a numeric datatype (int, double, ...) or the input \a v + * \param v the value to round and cast + * + * \note As a special feature, this function detectes whether one of T or TIn are unsigned and then cmpares against a limit of 0 instead of \c std::numeric_limits::min() . + */ +template +inline T jkqtp_bounded(TIn v) { + if (std::is_integral::value && std::is_integral::value && (std::is_signed::value!=std::is_signed::value)) { + return (vstd::numeric_limits::max())? std::numeric_limits::max() : static_cast(v)); + } else { + return (v::min()) ? std::numeric_limits::min() : ((v>std::numeric_limits::max())? std::numeric_limits::max() : static_cast(v)); + } } /** \brief compare two floats \a a and \a b for euqality, where any difference smaller than \a epsilon is seen as equality