From 2651ff5903893abf21d066c26ec1acc74c054e5b Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:33:41 -0400 Subject: [PATCH] added safety paranthesis --- machine_learning/kohonen_som_topology.c | 6 ++++-- machine_learning/kohonen_som_trace.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/machine_learning/kohonen_som_topology.c b/machine_learning/kohonen_som_topology.c index f318e91e..e01f966a 100644 --- a/machine_learning/kohonen_som_topology.c +++ b/machine_learning/kohonen_som_topology.c @@ -28,10 +28,12 @@ #endif #ifndef max -#define max(a, b) (a > b ? a : b) /**< shorthand for maximum value */ +#define max(a, b) (((a) > (b)) ? (a) : (b)) /**< shorthand for maximum value \ + */ #endif #ifndef min -#define min(a, b) (a < b ? a : b) /**< shorthand for minimum value */ +#define min(a, b) (((a) < (b)) ? (a) : (b)) /**< shorthand for minimum value \ + */ #endif /** to store info regarding 3D arrays */ diff --git a/machine_learning/kohonen_som_trace.c b/machine_learning/kohonen_som_trace.c index ec56f197..912215a6 100644 --- a/machine_learning/kohonen_som_trace.c +++ b/machine_learning/kohonen_som_trace.c @@ -9,8 +9,9 @@ * The algorithm creates a connected network of weights that closely * follows the given data points. This this creates a chain of nodes that * resembles the given input shape. + * \see kohonen_som_topology.c */ -#define _USE_MATH_DEFINES // required for MS Visual C +#define _USE_MATH_DEFINES /**< required for MS Visual C */ #include #include #include @@ -19,8 +20,14 @@ #include #endif -#define max(a, b) (a > b ? a : b) // shorthand for maximum value -#define min(a, b) (a < b ? a : b) // shorthand for minimum value +#ifndef max +#define max(a, b) (((a) > (b)) ? (a) : (b)) /**< shorthand for maximum value \ + */ +#endif +#ifndef min +#define min(a, b) (((a) < (b)) ? (a) : (b)) /**< shorthand for minimum value \ + */ +#endif /** * Helper function to generate a random number in a given interval.