jscript: Added new is_finite helper.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-01-27 20:43:11 +01:00 committed by Alexandre Julliard
parent b1197a15ec
commit e00708e3aa
4 changed files with 12 additions and 10 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -16,9 +16,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <math.h>
#include <assert.h>
@ -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;