summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-09-07 11:49:13 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2022-09-07 14:01:40 +0200
commit48a822fe60fa6cdb8d105604f4511bd7f7d69903 (patch)
tree071be88028dabf4e76ab42a2fa3cf103aa7d392c /include
parentca6888484e643e0c55918d9c882241e6dd6b734f (diff)
Use exactly two comparisons in fround
It is used extensively in drawinglayer; the typical path for values inside sal_Int32 range used three comparisons. Change-Id: Iafb09f06a746bb53a41585be4a5b1a701fa38057 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139555 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/basegfx/numeric/ftools.hxx12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/basegfx/numeric/ftools.hxx b/include/basegfx/numeric/ftools.hxx
index 14deaa059020..4f1bc1680000 100644
--- a/include/basegfx/numeric/ftools.hxx
+++ b/include/basegfx/numeric/ftools.hxx
@@ -37,11 +37,15 @@ namespace basegfx
*/
inline sal_Int32 fround( double fVal )
{
- if (fVal >= std::numeric_limits<sal_Int32>::max() - .5)
- return std::numeric_limits<sal_Int32>::max();
- else if (fVal <= std::numeric_limits<sal_Int32>::min() + .5)
+ if (fVal >= 0.0)
+ {
+ if (fVal >= std::numeric_limits<sal_Int32>::max() - .5)
+ return std::numeric_limits<sal_Int32>::max();
+ return static_cast<sal_Int32>(fVal + .5);
+ }
+ if (fVal <= std::numeric_limits<sal_Int32>::min() + .5)
return std::numeric_limits<sal_Int32>::min();
- return fVal > 0.0 ? static_cast<sal_Int32>( fVal + .5 ) : static_cast<sal_Int32>( fVal - .5 );
+ return static_cast<sal_Int32>(fVal - .5);
}
/** Round double to nearest integer