diff --git a/src/PJ_robin.c b/src/PJ_robin.c index 7514b32564..92aebfd32a 100644 --- a/src/PJ_robin.c +++ b/src/PJ_robin.c @@ -1,4 +1,5 @@ #define PJ_LIB__ +#include "proj_internal.h" #include "proj.h" #include "projects.h" @@ -80,7 +81,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ double dphi; (void) P; - i = (int)floor((dphi = fabs(lp.phi)) * C1); + dphi = fabs(lp.phi); + i = pj_is_nan(lp.phi) ? -1 : (int)floor(dphi * C1); if( i < 0 ){ proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return xy; @@ -115,7 +117,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ } } else { /* general problem */ /* in Y space, reduce to table interval */ - i = (int)floor(lp.phi * NODES); + i = pj_is_nan(lp.phi) ? -1 : (int)floor(lp.phi * NODES); if( i < 0 || i >= NODES ) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return lp; diff --git a/src/nad_intr.c b/src/nad_intr.c index b385410f58..dc245831ab 100644 --- a/src/nad_intr.c +++ b/src/nad_intr.c @@ -1,6 +1,8 @@ /* Determine nad table correction value */ #define PJ_LIB__ +#include "proj_internal.h" #include "projects.h" + LP nad_intr(LP t, struct CTABLE *ct) { LP val, frct; @@ -10,8 +12,11 @@ nad_intr(LP t, struct CTABLE *ct) { long index; int in; - indx.lam = (int)floor(t.lam /= ct->del.lam); - indx.phi = (int)floor(t.phi /= ct->del.phi); + t.lam /= ct->del.lam; + indx.lam = pj_is_nan(t.lam) ? 0 : (int)floor(t.lam); + t.phi /= ct->del.phi; + indx.phi = pj_is_nan(t.phi) ? 0 : (int)floor(t.phi); + frct.lam = t.lam - indx.lam; frct.phi = t.phi - indx.phi; val.lam = val.phi = HUGE_VAL; diff --git a/src/pj_internal.c b/src/pj_internal.c index 61905259f4..9cbbf20a5f 100644 --- a/src/pj_internal.c +++ b/src/pj_internal.c @@ -443,3 +443,15 @@ void proj_log_func (PJ_CONTEXT *ctx, void *app_data, PJ_LOG_FUNCTION logf) { if (0!=logf) ctx->logger = logf; } + + +/*****************************************************************************/ +int pj_is_nan (double val) { +/****************************************************************************** + Returns 0 if not a NaN and non-zero if val is a NaN. + + Provides an equivalent to isnan(). +******************************************************************************/ + /* cppcheck-suppress duplicateExpression */ + return val != val; +} diff --git a/src/proj_internal.h b/src/proj_internal.h index 75893c33b2..b3843a59f8 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -130,6 +130,8 @@ void proj_fileapi_set (PJ *P, void *fileapi); const char * const *proj_get_searchpath(void); int proj_get_path_count(void); +int pj_is_nan (double val); + #ifdef __cplusplus } #endif