From e00708e3aa058dceda858e874ec096a46814a16b Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 27 Jan 2016 20:43:11 +0100 Subject: [PATCH] jscript: Added new is_finite helper. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/global.c | 3 +-- dlls/jscript/jscript.h | 1 + dlls/jscript/jsutils.c | 7 ++++++- dlls/jscript/number.c | 11 ++++------- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index dbfb95bf599..1889dc83372 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -264,8 +264,7 @@ static HRESULT JSGlobal_isFinite(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, if(FAILED(hres)) return hres; - if(!isinf(n) && !isnan(n)) - ret = TRUE; + ret = is_finite(n); } if(r) diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 32a1be0325c..c0c546ad1fe 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -339,6 +339,7 @@ HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HI HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN; HRESULT double_to_string(double,jsstr_t**) DECLSPEC_HIDDEN; +BOOL is_finite(double) DECLSPEC_HIDDEN; typedef struct named_item_t { IDispatch *disp; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 85f573fd44b..59dbc65408f 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -53,6 +53,11 @@ const char *debugstr_jsval(const jsval_t v) return NULL; } +BOOL is_finite(double n) +{ + return !isnan(n) && !isinf(n); +} + #define MIN_BLOCK_SIZE 128 #define ARENA_FREE_FILLER 0xaa @@ -641,7 +646,7 @@ HRESULT to_int32(script_ctx_t *ctx, jsval_t v, INT *ret) if(FAILED(hres)) return hres; - *ret = isnan(n) || isinf(n) ? 0 : n; + *ret = is_finite(n) ? n : 0; return S_OK; } diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c index 0a648d05310..9b5d9a2da20 100644 --- a/dlls/jscript/number.c +++ b/dlls/jscript/number.c @@ -16,9 +16,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "config.h" -#include "wine/port.h" - #include #include @@ -257,7 +254,7 @@ static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u val = number->value; - if(radix==10 || isnan(val) || isinf(val)) { + if(radix==10 || !is_finite(val)) { hres = to_string(ctx, jsval_number(val), &str); if(FAILED(hres)) return hres; @@ -383,7 +380,7 @@ static HRESULT Number_toFixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un } val = number->value; - if(isinf(val) || isnan(val)) { + if(!is_finite(val)) { hres = to_string(ctx, jsval_number(val), &str); if(FAILED(hres)) return hres; @@ -424,7 +421,7 @@ static HRESULT Number_toExponential(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla } val = number->value; - if(isinf(val) || isnan(val)) { + if(!is_finite(val)) { hres = to_string(ctx, jsval_number(val), &str); if(FAILED(hres)) return hres; @@ -465,7 +462,7 @@ static HRESULT Number_toPrecision(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags } val = number->value; - if(isinf(val) || isnan(val) || !prec) { + if(!is_finite(val) || !prec) { hres = to_string(ctx, jsval_number(val), &str); if(FAILED(hres)) return hres;