Skip to content

Commit 4b009f9

Browse files
committedAug 24, 2017
Use std::round instead of qRound
Now that our minimum VS studio version allowed supports std::round, we should use that in place of Qt's qRound method. Because: - it doesn't truncate to int, resulting in unpredictable behaviour (refs #16925) - better to stick to standard c++ methods wherever possible, since they're likely better supported and optimised by the compilers - it's a tiny reduction to the barrier for entry to QGIS development (I'm sick of pointing out the need to use qRound during PR reviews!)
1 parent 50e8e1c commit 4b009f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1800
-1798
lines changed
 

‎python/core/qgis.sip

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ Compare two doubles using specified number of significant digits
153153
:rtype: bool
154154
%End
155155

156-
double qgsRound( double x );
157-
%Docstring
158-
A round function which returns a double to guard against overflows
159-
:rtype: float
160-
%End
161-
162156
double qgsRound( double number, double places );
163157
%Docstring
164158
Returns a double ``number``, rounded (as close as possible) to the specified number of ``places``.

‎src/analysis/raster/qgsalignraster.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030

3131
static double ceil_with_tolerance( double value )
3232
{
33-
if ( qAbs( value - qRound( value ) ) < 1e-6 )
34-
return qRound( value );
33+
if ( qAbs( value - std::round( value ) ) < 1e-6 )
34+
return std::round( value );
3535
else
3636
return qCeil( value );
3737
}
3838

3939
static double floor_with_tolerance( double value )
4040
{
41-
if ( qAbs( value - qRound( value ) ) < 1e-6 )
42-
return qRound( value );
41+
if ( qAbs( value - std::round( value ) ) < 1e-6 )
42+
return std::round( value );
4343
else
4444
return qFloor( value );
4545
}

0 commit comments

Comments
 (0)