-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] fix qgsRound for negative numbers. Fixes #20861
- Loading branch information
1 parent
774f025
commit cfdc8c2
Showing
2 changed files
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,8 +303,9 @@ inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 ) | |
*/ | ||
inline double qgsRound( double number, double places ) | ||
{ | ||
double m = ( number < 0.0 ) ? -1.0 : 1.0; | ||
double scaleFactor = std::pow( 10.0, places ); | ||
return std::trunc( number * scaleFactor + 0.5 ) / scaleFactor; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lbartoletti
Author
Member
|
||
return ( std::round( number * m * scaleFactor ) / scaleFactor ) * m; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@lbartoletti the test passes on my machine even without the
m
factor.I dind't really measure how much overhead this two lines are adding, but if we can avoid them let's do it. (use case: massive json generation where each and every coordinate goes through this function)