Skip to content

Commit abadb40

Browse files
committed
fix warning about truncating floating point values
warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value] _meetPointLon += 2*3.14159265358979323846 - abs(_meetPointLon); ^ note: use function 'std::abs' instead
1 parent 9499bc2 commit abadb40

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/Savegame/MovingTarget.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,15 @@ void MovingTarget::calculateMeetPoint()
254254
do
255255
{
256256
_meetPointLat += nx*sin(_meetPointLon) - ny*cos(_meetPointLon);
257-
if (abs(_meetPointLat) < M_PI/2) _meetPointLon += nz - (nx*cos(_meetPointLon) + ny*sin(_meetPointLon))*tan(_meetPointLat); else _meetPointLon += M_PI;
257+
// using std::abs instead of abs since abs can't handle floating point
258+
if (std::abs(_meetPointLat) < M_PI/2) _meetPointLon += nz - (nx*cos(_meetPointLon) + ny*sin(_meetPointLon))*tan(_meetPointLat); else _meetPointLon += M_PI;
258259
path += _speedRadian;
259260

260261
distance = acos(cos(_lat) * cos(_meetPointLat) * cos(_meetPointLon - _lon) + sin(_lat) * sin(_meetPointLat));
261262
} while (path < M_PI && distance - path*speedRatio > 0);
262263

263264
// Correction overflowing angles
264-
while (abs(_meetPointLon) > M_PI)
265+
while (std::abs(_meetPointLon) > M_PI)
265266
{
266267
if (_meetPointLon > 0)
267268
{
@@ -272,7 +273,7 @@ void MovingTarget::calculateMeetPoint()
272273
_meetPointLon += 2*M_PI;
273274
}
274275
}
275-
while (abs(_meetPointLat) > M_PI)
276+
while (std::abs(_meetPointLat) > M_PI)
276277
{
277278
if (_meetPointLat > 0)
278279
{
@@ -283,24 +284,24 @@ void MovingTarget::calculateMeetPoint()
283284
_meetPointLat += 2*M_PI;
284285
}
285286
}
286-
if (abs(_meetPointLat) > M_PI/2)
287+
if (std::abs(_meetPointLat) > M_PI/2)
287288
{
288289
if (_meetPointLat > 0)
289290
{
290-
_meetPointLat = 2*M_PI - abs(_meetPointLat);
291+
_meetPointLat = 2*M_PI - std::abs(_meetPointLat);
291292
}
292293
else
293294
{
294-
_meetPointLat = -(2*M_PI - abs(_meetPointLat));
295+
_meetPointLat = -(2*M_PI - std::abs(_meetPointLat));
295296
}
296297

297298
if (_meetPointLon > 0)
298299
{
299-
_meetPointLon -= 2*M_PI - abs(_meetPointLon);
300+
_meetPointLon -= 2*M_PI - std::abs(_meetPointLon);
300301
}
301302
else
302303
{
303-
_meetPointLon += 2*M_PI - abs(_meetPointLon);
304+
_meetPointLon += 2*M_PI - std::abs(_meetPointLon);
304305
}
305306
}
306307
}

0 commit comments

Comments
 (0)