summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-01-16 16:08:44 +0100
committerStephan Bergmann <sbergman@redhat.com>2018-01-17 08:38:08 +0100
commit9cb671f369cf5ce969bff4a84ef3e452419c736e (patch)
tree4b2cccb48da5915ca1bb48f8a13d1c595f3a9f26 /i18npool
parentbd29365d224ff1d34d4130703ddf8a33e487b6af (diff)
Use std::trunc instead of casting (to express intent more clearly)
If jday were guaranteed to be non-negative, the first could also be changed to jday = std::round(jday); but that would give different results for negative jday. So play it safe by assuming that jday might be negative, and that if it were, the original way of rounding was actually intended. Change-Id: I137ee659e738791a7d260ce86cba60cdbbc084a6 Reviewed-on: https://gerrit.libreoffice.org/48004 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/calendar/calendar_hijri.cxx8
1 files changed, 5 insertions, 3 deletions
diff --git a/i18npool/source/calendar/calendar_hijri.cxx b/i18npool/source/calendar/calendar_hijri.cxx
index 064d04e6d4d6..bee72af7e7e3 100644
--- a/i18npool/source/calendar/calendar_hijri.cxx
+++ b/i18npool/source/calendar/calendar_hijri.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <cmath>
#include <stdlib.h>
#include <math.h>
@@ -236,7 +238,7 @@ Calendar_hijri::ToGregorian(sal_Int32 *day, sal_Int32 *month, sal_Int32 *year)
jday = NewMoon(nmonth) + *day;
// Round-up
- jday = static_cast<double>(static_cast<sal_Int32>(jday + 0.5));
+ jday = std::trunc(jday + 0.5);
// Use algorithm from "Numerical Recipes in C"
getGregorianDay(static_cast<sal_Int32>(jday), day, month, year);
@@ -320,8 +322,8 @@ Calendar_hijri::getJulianDay(sal_Int32 day, sal_Int32 month, sal_Int32 year)
if( day + 31 * (month + 12 * year) >= gregcal ) {
double ja;
- ja = static_cast<sal_Int32>(0.01 * jy);
- intgr += static_cast<sal_Int32>(2 - ja + static_cast<sal_Int32>(0.25 * ja));
+ ja = std::trunc(0.01 * jy);
+ intgr += static_cast<sal_Int32>(2 - ja + std::trunc(0.25 * ja));
}
return intgr;