diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index ad39b450dd3..c9bd6c041cf 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -405,6 +405,19 @@ static inline DOUBLE num_val(const VARIANT *v) return V_VT(v) == VT_I4 ? V_I4(v) : V_R8(v); } +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif + +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif + +static inline BOOL is_int32(double d) +{ + return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d; +} + static inline void num_set_int(VARIANT *v, INT i) { V_VT(v) = VT_I4; @@ -413,7 +426,7 @@ static inline void num_set_int(VARIANT *v, INT i) static inline void num_set_val(VARIANT *v, DOUBLE d) { - if(d == (DOUBLE)(INT)d) { + if(is_int32(d)) { V_VT(v) = VT_I4; V_I4(v) = d; }else { diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c index 0cf12700277..0f6b0e2834d 100644 --- a/dlls/jscript/regexp.c +++ b/dlls/jscript/regexp.c @@ -3531,7 +3531,7 @@ static INT index_from_var(script_ctx_t *ctx, VARIANT *v) } n = floor(n); - return (double)(INT)n == n ? n : 0; + return is_int32(n) ? n : 0; } static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,