NEW add jkqtp_roundToDigits()

This commit is contained in:
jkriege2 2024-01-21 22:08:14 +01:00
parent 2559097fd2
commit 11bafa52e4
2 changed files with 19 additions and 0 deletions

View File

@ -29,6 +29,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API</li> <li>NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API</li>
<li>NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH</li> <li>NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH</li>
<li>NEW add JKQTPExpected datatype</li> <li>NEW add JKQTPExpected datatype</li>
<li>NEW add jkqtp_roundToDigits()</li>
</ul></li> </ul></li>
<li>JKQTPlotter:<ul> <li>JKQTPlotter:<ul>

View File

@ -143,6 +143,24 @@ inline T jkqtp_roundTo(const double& v) {
return static_cast<T>(round(v)); return static_cast<T>(round(v));
} }
/** \brief round a double \a v using round() to a given number of decimal digits
* \ingroup jkqtptools_math_basic
*
* \param v the value to round and cast
* \param decDigits number of decimal digits, i.e. precision of the result
*
* this is equivalent to
* \code
* round(v * pow(10.0,(double)decDigits))/pow(10.0,(double)decDigits);
* \endcode
*
* \callergraph
*/
inline double jkqtp_roundToDigits(const double& v, const int decDigits) {
const double fac=pow(10.0,(double)decDigits);
return round(v * fac) / fac;
}
/** \brief round a double \a v using ceil() and convert it to a specified type T (static_cast!) /** \brief round a double \a v using ceil() and convert it to a specified type T (static_cast!)
* \ingroup jkqtptools_math_basic * \ingroup jkqtptools_math_basic
* *