[libcamera-devel,06/10] ipa: replaces abs() with std::abs()
diff mbox series

Message ID 20221027055515.321791-7-nicholas@rothemail.net
State Superseded
Headers show
Series
  • [libcamera-devel,01/10] ipa: workaround libcxx duration limitation
Related show

Commit Message

Nicolas Dufresne via libcamera-devel Oct. 27, 2022, 5:55 a.m. UTC
From: Nicholas Roth <nicholas@rothemail.net>

pwl.cpp uses abs() instead of std::abs(), which causes unexpected
behavior in the Clang compiler used for Android. Replace with
C++-standard absolute value function std::abs(), which supports
double-precision absolute values in a standard way.

Signed-off-by: Nicholas Roth <nicholas@rothemail.net>
---
 src/ipa/raspberrypi/controller/pwl.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jacopo Mondi Oct. 27, 2022, 4:49 p.m. UTC | #1
Hi Nicholas

On Thu, Oct 27, 2022 at 12:55:11AM -0500, Nicholas Roth via libcamera-devel wrote:
> From: Nicholas Roth <nicholas@rothemail.net>
>
> pwl.cpp uses abs() instead of std::abs(), which causes unexpected
> behavior in the Clang compiler used for Android. Replace with
> C++-standard absolute value function std::abs(), which supports
> double-precision absolute values in a standard way.
>
> Signed-off-by: Nicholas Roth <nicholas@rothemail.net>

Thanks
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>


Actually, to be pedantic, I would have
ipa: raspberry: ..
in the subject line as the change touches a single implementation.
But this is certainly a detail

> ---
>  src/ipa/raspberrypi/controller/pwl.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/ipa/raspberrypi/controller/pwl.cpp b/src/ipa/raspberrypi/controller/pwl.cpp
> index c59f5fa1..70c2e24b 100644
> --- a/src/ipa/raspberrypi/controller/pwl.cpp
> +++ b/src/ipa/raspberrypi/controller/pwl.cpp
> @@ -6,6 +6,7 @@
>   */
>
>  #include <cassert>
> +#include <cmath>
>  #include <stdexcept>
>
>  #include "pwl.h"
> @@ -168,7 +169,7 @@ Pwl Pwl::compose(Pwl const &other, const double eps) const
>  	while (thisSpan != (int)points_.size() - 1) {
>  		double dx = points_[thisSpan + 1].x - points_[thisSpan].x,
>  		       dy = points_[thisSpan + 1].y - points_[thisSpan].y;
> -		if (abs(dy) > eps &&
> +		if (std::abs(dy) > eps &&
>  		    otherSpan + 1 < (int)other.points_.size() &&
>  		    points_[thisSpan + 1].y >=
>  			    other.points_[otherSpan + 1].x + eps) {
> @@ -181,7 +182,7 @@ Pwl Pwl::compose(Pwl const &other, const double eps) const
>  				 points_[thisSpan].y) *
>  					dx / dy;
>  			thisY = other.points_[++otherSpan].x;
> -		} else if (abs(dy) > eps && otherSpan > 0 &&
> +		} else if (std::abs(dy) > eps && otherSpan > 0 &&
>  			   points_[thisSpan + 1].y <=
>  				   other.points_[otherSpan - 1].x - eps) {
>  			/*
> --
> 2.34.1
>

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/pwl.cpp b/src/ipa/raspberrypi/controller/pwl.cpp
index c59f5fa1..70c2e24b 100644
--- a/src/ipa/raspberrypi/controller/pwl.cpp
+++ b/src/ipa/raspberrypi/controller/pwl.cpp
@@ -6,6 +6,7 @@ 
  */
 
 #include <cassert>
+#include <cmath>
 #include <stdexcept>
 
 #include "pwl.h"
@@ -168,7 +169,7 @@  Pwl Pwl::compose(Pwl const &other, const double eps) const
 	while (thisSpan != (int)points_.size() - 1) {
 		double dx = points_[thisSpan + 1].x - points_[thisSpan].x,
 		       dy = points_[thisSpan + 1].y - points_[thisSpan].y;
-		if (abs(dy) > eps &&
+		if (std::abs(dy) > eps &&
 		    otherSpan + 1 < (int)other.points_.size() &&
 		    points_[thisSpan + 1].y >=
 			    other.points_[otherSpan + 1].x + eps) {
@@ -181,7 +182,7 @@  Pwl Pwl::compose(Pwl const &other, const double eps) const
 				 points_[thisSpan].y) *
 					dx / dy;
 			thisY = other.points_[++otherSpan].x;
-		} else if (abs(dy) > eps && otherSpan > 0 &&
+		} else if (std::abs(dy) > eps && otherSpan > 0 &&
 			   points_[thisSpan + 1].y <=
 				   other.points_[otherSpan - 1].x - eps) {
 			/*