From fe2501fdc3bc2f824676f2daec4921a093d78a7f Mon Sep 17 00:00:00 2001 From: reneSchm <49305466+reneSchm@users.noreply.github.com> Date: Thu, 11 Apr 2024 09:16:52 +0200 Subject: [PATCH] fix indents, improve performance slightly --- cpp/memilio/math/floating_point.h | 136 +++++++++++++++--------------- 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/cpp/memilio/math/floating_point.h b/cpp/memilio/math/floating_point.h index 1632ee7f9d..38c96b05bf 100644 --- a/cpp/memilio/math/floating_point.h +++ b/cpp/memilio/math/floating_point.h @@ -17,8 +17,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef EPI_MATH_FLOATING_POINT_H -#define EPI_MATH_FLOATING_POINT_H +#ifndef MIO_MATH_FLOATING_POINT_H +#define MIO_MATH_FLOATING_POINT_H #include #include @@ -26,12 +26,13 @@ namespace mio { + /** - * maximum absolute value of two numbers. - * @param v1 first number - * @param v2 second number - * @return maximum absolute value between v1 and v2 - */ + * maximum absolute value of two numbers. + * @param v1 first number + * @param v2 second number + * @return maximum absolute value between v1 and v2 + */ template T abs_max(T v1, T v2) { @@ -39,15 +40,15 @@ T abs_max(T v1, T v2) } /** - * compare two floating point values for equality with tolerances. - * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. - * Otherwise use relative tolerance. If unsure, use both. - * @param v1 first floating point value - * @param v2 second floating point value - * @param abs_tol maximum allowed absolute difference, default 0. - * @param rel_tol maximum allowed relative difference, default numeric_limits::min. - * @return true if v1 is within the specified relative OR absolute tolerance of v2 - */ + * compare two floating point values for equality with tolerances. + * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. + * Otherwise use relative tolerance. If unsure, use both. + * @param v1 first floating point value + * @param v2 second floating point value + * @param abs_tol maximum allowed absolute difference, default 0. + * @param rel_tol maximum allowed relative difference, default numeric_limits::min. + * @return true if v1 is within the specified relative OR absolute tolerance of v2 + */ template bool floating_point_equal(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_limits::min()) { @@ -56,18 +57,18 @@ bool floating_point_equal(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_li } /** - * compare two floating point values with tolerances. - * v1 < v2 if - * a) v1 not == v2 within tolerances and - * b) v1 not > v2. - * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. - * Use relative tolerance (or both) otherwise. - * @param v1 first floating point value - * @param v2 second floating point value - * @param abs_tol maximum allowed absolute difference for equality, default 0. - * @param rel_tol maximum allowed relative difference for equality, default numeric_limits::min. - * @return true if v1 is less than v2 and not within relative or absolute tolerance of v2. - */ + * compare two floating point values with tolerances. + * v1 < v2 if + * a) v1 not == v2 within tolerances and + * b) v1 not > v2. + * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. + * Use relative tolerance (or both) otherwise. + * @param v1 first floating point value + * @param v2 second floating point value + * @param abs_tol maximum allowed absolute difference for equality, default 0. + * @param rel_tol maximum allowed relative difference for equality, default numeric_limits::min. + * @return true if v1 is less than v2 and not within relative or absolute tolerance of v2. + */ template bool floating_point_less(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_limits::min()) { @@ -76,18 +77,18 @@ bool floating_point_less(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_lim } /** - * compare two floating point values with tolerances. - * v1 > v2 if - * a) v1 not == v2 within tolerances AND - * b) v1 not < v2. - * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. - * Use relative tolerance (or both) otherwise. - * @param v1 first floating point value - * @param v2 second floating point value - * @param abs_tol maximum allowed absolute difference, default 0. - * @param rel_tol maximum allowed relative difference, default numeric_limits::min. - * @return true if v1 is greater than v2 and not within absolute or relative tolerance of v2. - */ + * compare two floating point values with tolerances. + * v1 > v2 if + * a) v1 not == v2 within tolerances AND + * b) v1 not < v2. + * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. + * Use relative tolerance (or both) otherwise. + * @param v1 first floating point value + * @param v2 second floating point value + * @param abs_tol maximum allowed absolute difference, default 0. + * @param rel_tol maximum allowed relative difference, default numeric_limits::min. + * @return true if v1 is greater than v2 and not within absolute or relative tolerance of v2. + */ template bool floating_point_greater(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_limits::min()) { @@ -95,42 +96,43 @@ bool floating_point_greater(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_ } /** - * compare two floating point values with tolerances. - * v1 <= v2 if - * a) v1 < v2 OR - * b) v1 == v2 within tolerances. - * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. - * Use relative tolerance (or both) otherwise. - * @param v1 first floating point value - * @param v2 second floating point value - * @param abs_tol maximum allowed absolute difference, default 0. - * @param rel_tol maximum allowed relative difference, default numeric_limits::min. - * @return true if v1 is less than v2 or within relative or absolute tolerances of v2. - */ + * compare two floating point values with tolerances. + * v1 <= v2 if + * a) v1 < v2 OR + * b) v1 == v2 within tolerances. + * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. + * Use relative tolerance (or both) otherwise. + * @param v1 first floating point value + * @param v2 second floating point value + * @param abs_tol maximum allowed absolute difference, default 0. + * @param rel_tol maximum allowed relative difference, default numeric_limits::min. + * @return true if v1 is less than v2 or within relative or absolute tolerances of v2. + */ template bool floating_point_less_equal(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_limits::min()) { - return floating_point_less(v1, v2, abs_tol, rel_tol) || floating_point_equal(v1, v2, abs_tol, rel_tol); + return !floating_point_greater(v1, v2, abs_tol, rel_tol); } /** - * compare two floating point values with tolerances. - * v1 >= v2 if - * a) v1 > v2 OR - * b) v1 == v2 within tolerances. - * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. - * Use relative tolerance (or both) otherwise. - * @param v1 first floating point value - * @param v2 second floating point value - * @param abs_tol maximum allowed absolute difference, default 0. - * @param rel_tol maximum allowed relative difference, default numeric_limits::min. - * @return true if v1 is greater than v2 or within absolute or relative tolerance of v2. - */ + * compare two floating point values with tolerances. + * v1 >= v2 if + * a) v1 > v2 OR + * b) v1 == v2 within tolerances. + * Use absolute tolerance for comparisons with zero or if you know the magnitude of the values. + * Use relative tolerance (or both) otherwise. + * @param v1 first floating point value + * @param v2 second floating point value + * @param abs_tol maximum allowed absolute difference, default 0. + * @param rel_tol maximum allowed relative difference, default numeric_limits::min. + * @return true if v1 is greater than v2 or within absolute or relative tolerance of v2. + */ template bool floating_point_greater_equal(T v1, T v2, T abs_tol = 0, T rel_tol = std::numeric_limits::min()) { - return floating_point_greater(v1, v2, abs_tol, rel_tol) || floating_point_equal(v1, v2, abs_tol, rel_tol); + return !floating_point_less(v1, v2, abs_tol, rel_tol); } + } // namespace mio -#endif +#endif // MIO_MATH_FLOATING_POINT_H