Skip to content

Commit 3ffdb6c

Browse files
committed
Introduce qgsRound since std::round is available only in C++11 onwards
(cherry-picked from 468012a)
1 parent f16328a commit 3ffdb6c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/core/qgis.h

+8
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
351351
qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) );
352352
}
353353

354+
//
355+
// a round function which returns a double to guard against overflows
356+
//
357+
inline double qgsRound( double x )
358+
{
359+
return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
360+
}
361+
354362
bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
355363

356364
bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );

0 commit comments

Comments
 (0)