[2/2] libcamera: Replace last users of math.c
diff mbox series

Message ID 20240926100640.3504-2-laurent.pinchart@ideasonboard.com
State Accepted
Commit 8d22064082aa2c8b451a6a4cc1ea6078aa1d1ce7
Headers show
Series
  • [1/2] ipa: rpi: Replace last users of math.c
Related show

Commit Message

Laurent Pinchart Sept. 26, 2024, 10:06 a.m. UTC
As described in the coding style document, libcamera favours <cmath>
over <math.h>. Replace the last few occurrences of the latter with the
former and adapt the code accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/pipeline/ipu3/cio2.cpp   | 4 ++--
 src/libcamera/sensor/camera_sensor.cpp | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Kieran Bingham Sept. 26, 2024, 10:35 a.m. UTC | #1
in $SUBJECT s/c$/h/

Quoting Laurent Pinchart (2024-09-26 11:06:40)
> As described in the coding style document, libcamera favours <cmath>
> over <math.h>. Replace the last few occurrences of the latter with the
> former and adapt the code accordingly.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/libcamera/pipeline/ipu3/cio2.cpp   | 4 ++--
>  src/libcamera/sensor/camera_sensor.cpp | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
> index 81a7a8ab01b8..74a5d93f88ae 100644
> --- a/src/libcamera/pipeline/ipu3/cio2.cpp
> +++ b/src/libcamera/pipeline/ipu3/cio2.cpp
> @@ -7,8 +7,8 @@
>  
>  #include "cio2.h"
>  
> +#include <cmath>
>  #include <limits>
> -#include <math.h>
>  
>  #include <linux/media-bus-format.h>
>  
> @@ -304,7 +304,7 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector<unsigned int>
>                          * comparing it with a single precision digit is enough.
>                          */
>                         ratio = static_cast<unsigned int>(ratio * 10) / 10.0;
> -                       float ratioDiff = fabsf(ratio - desiredRatio);
> +                       float ratioDiff = std::abs(ratio - desiredRatio);
>                         unsigned int area = sz.width * sz.height;
>                         unsigned int areaDiff = area - desiredArea;
>  
> diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
> index 4a990bb994b9..1b224f1989fe 100644
> --- a/src/libcamera/sensor/camera_sensor.cpp
> +++ b/src/libcamera/sensor/camera_sensor.cpp
> @@ -8,9 +8,9 @@
>  #include "libcamera/internal/camera_sensor.h"
>  
>  #include <algorithm>
> +#include <cmath>
>  #include <float.h>
>  #include <limits.h>
> -#include <math.h>
>  #include <string.h>
>  
>  #include <libcamera/base/utils.h>
> @@ -719,7 +719,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
>                                 continue;
>  
>                         float ratio = static_cast<float>(sz.width) / sz.height;
> -                       float ratioDiff = fabsf(ratio - desiredRatio);
> +                       float ratioDiff = std::abs(ratio - desiredRatio);
>                         unsigned int area = sz.width * sz.height;
>                         unsigned int areaDiff = area - desiredArea;
>  
> -- 
> Regards,
> 
> Laurent Pinchart
>
Naushir Patuck Sept. 30, 2024, 7:34 a.m. UTC | #2
Hi Laurent,

On Thu, 26 Sept 2024 at 11:06, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> As described in the coding style document, libcamera favours <cmath>
> over <math.h>. Replace the last few occurrences of the latter with the
> former and adapt the code accordingly.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

> ---
>  src/libcamera/pipeline/ipu3/cio2.cpp   | 4 ++--
>  src/libcamera/sensor/camera_sensor.cpp | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
> index 81a7a8ab01b8..74a5d93f88ae 100644
> --- a/src/libcamera/pipeline/ipu3/cio2.cpp
> +++ b/src/libcamera/pipeline/ipu3/cio2.cpp
> @@ -7,8 +7,8 @@
>
>  #include "cio2.h"
>
> +#include <cmath>
>  #include <limits>
> -#include <math.h>
>
>  #include <linux/media-bus-format.h>
>
> @@ -304,7 +304,7 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector<unsigned int>
>                          * comparing it with a single precision digit is enough.
>                          */
>                         ratio = static_cast<unsigned int>(ratio * 10) / 10.0;
> -                       float ratioDiff = fabsf(ratio - desiredRatio);
> +                       float ratioDiff = std::abs(ratio - desiredRatio);
>                         unsigned int area = sz.width * sz.height;
>                         unsigned int areaDiff = area - desiredArea;
>
> diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
> index 4a990bb994b9..1b224f1989fe 100644
> --- a/src/libcamera/sensor/camera_sensor.cpp
> +++ b/src/libcamera/sensor/camera_sensor.cpp
> @@ -8,9 +8,9 @@
>  #include "libcamera/internal/camera_sensor.h"
>
>  #include <algorithm>
> +#include <cmath>
>  #include <float.h>
>  #include <limits.h>
> -#include <math.h>
>  #include <string.h>
>
>  #include <libcamera/base/utils.h>
> @@ -719,7 +719,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
>                                 continue;
>
>                         float ratio = static_cast<float>(sz.width) / sz.height;
> -                       float ratioDiff = fabsf(ratio - desiredRatio);
> +                       float ratioDiff = std::abs(ratio - desiredRatio);
>                         unsigned int area = sz.width * sz.height;
>                         unsigned int areaDiff = area - desiredArea;
>
> --
> Regards,
>
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
index 81a7a8ab01b8..74a5d93f88ae 100644
--- a/src/libcamera/pipeline/ipu3/cio2.cpp
+++ b/src/libcamera/pipeline/ipu3/cio2.cpp
@@ -7,8 +7,8 @@ 
 
 #include "cio2.h"
 
+#include <cmath>
 #include <limits>
-#include <math.h>
 
 #include <linux/media-bus-format.h>
 
@@ -304,7 +304,7 @@  V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector<unsigned int>
 			 * comparing it with a single precision digit is enough.
 			 */
 			ratio = static_cast<unsigned int>(ratio * 10) / 10.0;
-			float ratioDiff = fabsf(ratio - desiredRatio);
+			float ratioDiff = std::abs(ratio - desiredRatio);
 			unsigned int area = sz.width * sz.height;
 			unsigned int areaDiff = area - desiredArea;
 
diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp
index 4a990bb994b9..1b224f1989fe 100644
--- a/src/libcamera/sensor/camera_sensor.cpp
+++ b/src/libcamera/sensor/camera_sensor.cpp
@@ -8,9 +8,9 @@ 
 #include "libcamera/internal/camera_sensor.h"
 
 #include <algorithm>
+#include <cmath>
 #include <float.h>
 #include <limits.h>
-#include <math.h>
 #include <string.h>
 
 #include <libcamera/base/utils.h>
@@ -719,7 +719,7 @@  V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
 				continue;
 
 			float ratio = static_cast<float>(sz.width) / sz.height;
-			float ratioDiff = fabsf(ratio - desiredRatio);
+			float ratioDiff = std::abs(ratio - desiredRatio);
 			unsigned int area = sz.width * sz.height;
 			unsigned int areaDiff = area - desiredArea;