Skip to content

Commit fd84f7b

Browse files
committed
LLSQ: Replace sqrt by std::sqrt
This should fix warnings from LGTM: Multiplication result may overflow 'float' before it is converted to 'double'. Signed-off-by: Stefan Weil <[email protected]>
1 parent 7c2af45 commit fd84f7b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/ccstruct/linlsq.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: linlsq.cpp (Formerly llsq.c)
33
* Description: Linear Least squares fitting code.
44
* Author: Ray Smith
5-
* Created: Thu Sep 12 08:44:51 BST 1991
65
*
76
* (C) Copyright 1991, Hewlett-Packard Ltd.
87
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +17,7 @@
1817
**********************************************************************/
1918

2019
#include <cstdio>
21-
#include <cmath>
20+
#include <cmath> // for std::sqrt
2221
#include "errcode.h"
2322
#include "linlsq.h"
2423

@@ -135,7 +134,7 @@ double LLSQ::rms(double m, double c) const { // get error
135134
error = sigyy + m * (m * sigxx + 2 * (c * sigx - sigxy)) + c *
136135
(total_weight * c - 2 * sigy);
137136
if (error >= 0)
138-
error = sqrt(error / total_weight); // sqrt of mean
137+
error = std::sqrt(error / total_weight); // sqrt of mean
139138
else
140139
error = 0;
141140
} else {
@@ -158,7 +157,7 @@ double LLSQ::pearson() const { // get correlation
158157
if (covar != 0.0) {
159158
double var_product = x_variance() * y_variance();
160159
if (var_product > 0.0)
161-
r = covar / sqrt(var_product);
160+
r = covar / std::sqrt(var_product);
162161
}
163162
return r;
164163
}
@@ -196,9 +195,9 @@ FCOORD LLSQ::mean_point() const {
196195
double LLSQ::rms_orth(const FCOORD &dir) const {
197196
FCOORD v = !dir;
198197
v.normalise();
199-
return sqrt(v.x() * v.x() * x_variance() +
200-
2 * v.x() * v.y() * covariance() +
201-
v.y() * v.y() * y_variance());
198+
return std::sqrt(v.x() * v.x() * x_variance() +
199+
2 * v.x() * v.y() * covariance() +
200+
v.y() * v.y() * y_variance());
202201
}
203202

204203
// Returns the direction of the fitted line as a unit vector, using the

0 commit comments

Comments
 (0)