[Libreoffice-commits] core.git: i18npool/source
Stephan Bergmann
sbergman at redhat.com
Wed Jan 17 07:38:30 UTC 2018
i18npool/source/calendar/calendar_hijri.cxx | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
New commits:
commit 9cb671f369cf5ce969bff4a84ef3e452419c736e
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue Jan 16 16:08:44 2018 +0100
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 at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
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;
More information about the Libreoffice-commits
mailing list