jscript: Added NaN handling to Math.min and Math.max.
This commit is contained in:
parent
531f8336a8
commit
2e075e9862
|
@ -16,6 +16,9 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "wine/port.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "jscript.h"
|
||||
|
@ -222,11 +225,10 @@ static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
|
|||
|
||||
TRACE("\n");
|
||||
|
||||
/* FIXME: Handle NaN */
|
||||
|
||||
if(!arg_cnt(dp)) {
|
||||
FIXME("arg_cnt = 0\n");
|
||||
return E_NOTIMPL;
|
||||
if(retv)
|
||||
num_set_inf(retv, FALSE);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
|
||||
|
@ -240,7 +242,7 @@ static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
|
|||
return hres;
|
||||
|
||||
d = num_val(&v);
|
||||
if(d > max)
|
||||
if(d > max || isnan(d))
|
||||
max = d;
|
||||
}
|
||||
|
||||
|
@ -260,11 +262,10 @@ static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
|
|||
|
||||
TRACE("\n");
|
||||
|
||||
/* FIXME: Handle NaN */
|
||||
|
||||
if(!arg_cnt(dp)) {
|
||||
FIXME("arg_cnt = 0\n");
|
||||
return E_NOTIMPL;
|
||||
if(retv)
|
||||
num_set_inf(retv, TRUE);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
|
||||
|
@ -278,7 +279,7 @@ static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
|
|||
return hres;
|
||||
|
||||
d = num_val(&v);
|
||||
if(d < min)
|
||||
if(d < min || isnan(d))
|
||||
min = d;
|
||||
}
|
||||
|
||||
|
|
|
@ -368,6 +368,12 @@ ok(tmp === 1, "Math.min(1) = " + tmp);
|
|||
tmp = Math.min(1, false);
|
||||
ok(tmp === 0, "Math.min(1, false) = " + tmp);
|
||||
|
||||
tmp = Math.min();
|
||||
ok(tmp === Infinity, "Math.min() = " + tmp);
|
||||
|
||||
tmp = Math.min(1, NaN, -Infinity, false);
|
||||
ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
|
||||
|
||||
tmp = Math.min(1, false, true, null, -3);
|
||||
ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
|
||||
|
||||
|
@ -380,6 +386,12 @@ ok(tmp === 1, "Math.max(true, 0) = " + tmp);
|
|||
tmp = Math.max(-2, false, true, null, 1);
|
||||
ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
|
||||
|
||||
tmp = Math.max();
|
||||
ok(tmp === -Infinity, "Math.max() = " + tmp);
|
||||
|
||||
tmp = Math.max(true, NaN, 0);
|
||||
ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
|
||||
|
||||
tmp = Math.round(0.5);
|
||||
ok(tmp === 1, "Math.round(0.5) = " + tmp);
|
||||
|
||||
|
|
Loading…
Reference in New Issue