aboutsummaryrefslogtreecommitdiff
path: root/src/PJ_unitconvert.c
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2018-05-06 17:43:26 +0300
committerKristian Evers <kristianevers@gmail.com>2018-05-08 09:16:07 +0200
commit58cbb9fe4f89b9febd780f7bdcfa4c2bb74a723e (patch)
treedec50c945b01d09c5cf94d0665a6996e2d34ae5d /src/PJ_unitconvert.c
parent8fef2126f1c9fa17b79e6669f4457c299c0e33bf (diff)
downloadPROJ-58cbb9fe4f89b9febd780f7bdcfa4c2bb74a723e.tar.gz
PROJ-58cbb9fe4f89b9febd780f7bdcfa4c2bb74a723e.zip
Replace int typecasts with calls to lround to avoid bad conversions on NaN input. Added test to check for those cases.
Diffstat (limited to 'src/PJ_unitconvert.c')
-rw-r--r--src/PJ_unitconvert.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/PJ_unitconvert.c b/src/PJ_unitconvert.c
index a076b76c..53bf5e81 100644
--- a/src/PJ_unitconvert.c
+++ b/src/PJ_unitconvert.c
@@ -66,6 +66,8 @@ Last update: 2017-05-16
#define PJ_LIB__
#include <time.h>
#include <errno.h>
+
+#include "proj_math.h"
#include "proj_internal.h"
#include "projects.h"
@@ -152,14 +154,14 @@ static double decimalyear_to_mjd(double decimalyear) {
/***********************************************************************
Epoch of modified julian date is 1858-11-16 00:00
************************************************************************/
- int year;
+ long year;
double fractional_year;
double mjd;
if( decimalyear < -10000 || decimalyear > 10000 )
return 0;
- year = (int)floor(decimalyear);
+ year = lround(floor(decimalyear));
fractional_year = decimalyear - year;
mjd = (year - 1859)*365 + 14 + 31;
mjd += fractional_year*days_in_year(year);
@@ -228,9 +230,9 @@ static double yyyymmdd_to_mjd(double yyyymmdd) {
Date given in YYYY-MM-DD format.
************************************************************************/
- int year = (int)floor( yyyymmdd / 10000 );
- int month = (int)floor((yyyymmdd - year*10000) / 100);
- int day = (int)floor( yyyymmdd - year*10000 - month*100);
+ long year = lround(floor( yyyymmdd / 10000 ));
+ long month = lround(floor((yyyymmdd - year*10000) / 100));
+ long day = lround(floor( yyyymmdd - year*10000 - month*100));
double mjd = daynumber_in_year(year, month, day);
for (year -= 1; year > 1858; year--)