vbscript: Implemented Sgn.
This commit is contained in:
parent
393f4bc547
commit
0b13d721c2
|
@ -182,35 +182,15 @@ HRESULT to_int(VARIANT *v, int *ret)
|
|||
|
||||
static HRESULT to_double(VARIANT *v, double *ret)
|
||||
{
|
||||
switch(V_VT(v)) {
|
||||
case VT_I2:
|
||||
*ret = V_I2(v);
|
||||
break;
|
||||
case VT_I4:
|
||||
*ret = V_I4(v);
|
||||
break;
|
||||
case VT_R4:
|
||||
*ret = V_R4(v);
|
||||
break;
|
||||
case VT_R8:
|
||||
*ret = V_R8(v);
|
||||
break;
|
||||
case VT_BSTR: {
|
||||
VARIANT dst;
|
||||
HRESULT hres;
|
||||
|
||||
V_VT(&dst) = VT_EMPTY;
|
||||
hres = VariantChangeType(&dst, v, VARIANT_LOCALBOOL, VT_R8);
|
||||
hres = VariantChangeType(&dst, v, 0, VT_R8);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
*ret = V_R8(&dst);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
FIXME("arg %s not supported\n", debugstr_variant(v));
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
*ret = V_R8(&dst);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -1284,8 +1264,23 @@ static HRESULT Global_Int(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIA
|
|||
|
||||
static HRESULT Global_Sgn(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
double v;
|
||||
short val;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("(%s)\n", debugstr_variant(arg));
|
||||
|
||||
assert(args_cnt == 1);
|
||||
|
||||
if(V_VT(arg) == VT_NULL)
|
||||
return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
|
||||
|
||||
hres = to_double(arg, &v);
|
||||
if (FAILED(hres))
|
||||
return hres;
|
||||
|
||||
val = v == 0 ? 0 : (v > 0 ? 1 : -1);
|
||||
return return_short(res, val);
|
||||
}
|
||||
|
||||
static HRESULT Global_Now(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
|
||||
|
|
|
@ -878,4 +878,35 @@ Call ok(getVT(VarType(CBool(0.5))) = "VT_I2", "getVT(VarType(CBool(0.5))) = " &
|
|||
Call ok(VarType(CByte(255)) = vbByte, "VarType(CByte(255)) = " & VarType(CByte(255)))
|
||||
Call ok(getVT(VarType(CByte(255))) = "VT_I2", "getVT(VarType(CByte(255))) = " & getVT(VarType(CByte(255))))
|
||||
|
||||
Call ok(Sgn(Empty) = 0, "Sgn(MyEmpty) = " & Sgn(Empty))
|
||||
Call ok(getVT(Sgn(Empty)) = "VT_I2", "getVT(Sgn(MyEmpty)) = " & getVT(Sgn(Empty)))
|
||||
Call ok(Sgn(0) = 0, "Sgn(0) = " & Sgn(0))
|
||||
Call ok(getVT(Sgn(0)) = "VT_I2", "getVT(Sgn(0)) = " & getVT(Sgn(0)))
|
||||
Call ok(Sgn(-32769) = -1, "Sgn(-32769) = " & Sgn(-32769))
|
||||
Call ok(getVT(Sgn(-32769)) = "VT_I2", "getVT(Sgn(-32769)) = " & getVT(Sgn(-32769)))
|
||||
Call ok(Sgn(CSng(-0.5)) = -1, "Sgn(CSng(-0.5)) = " & Sgn(CSng(-0.5)))
|
||||
Call ok(getVT(Sgn(CSng(-0.5))) = "VT_I2", "getVT(Sgn(CSng(-0.5))) = " & getVT(Sgn(CSng(-0.5))))
|
||||
Call ok(Sgn(0.5) = 1, "Sgn(0.5) = " & Sgn(0.5))
|
||||
Call ok(getVT(Sgn(0.5)) = "VT_I2", "getVT(Sgn(0.5)) = " & getVT(Sgn(0.5)))
|
||||
Call ok(Sgn(CCur(-1)) = -1, "Sgn(CCur(-1)) = " & Sgn(CCur(-1)))
|
||||
Call ok(getVT(Sgn(CCur(-1))) = "VT_I2", "getVT(Sgn(CCur(-1))) = " & getVT(Sgn(CCur(-1))))
|
||||
Call ok(Sgn(CStr(-1)) = -1, "Sgn(CStr(-1)) = " & Sgn(CStr(-1)))
|
||||
Call ok(getVT(Sgn(CStr(-1))) = "VT_I2", "getVT(Sgn(CStr(-1))) = " & getVT(Sgn(CStr(-1))))
|
||||
Call ok(Sgn(False) = 0, "Sgn(False) = " & Sgn(False))
|
||||
Call ok(getVT(Sgn(False)) = "VT_I2", "getVT(Sgn(False)) = " & getVT(Sgn(False)))
|
||||
Call ok(Sgn(True) = -1, "Sgn(True) = " & Sgn(True))
|
||||
Call ok(getVT(Sgn(True)) = "VT_I2", "getVT(Sgn(True)) = " & getVT(Sgn(True)))
|
||||
Call ok(Sgn(CByte(1)) = 1, "Sgn(CByte(1)) = " & Sgn(CByte(1)))
|
||||
Call ok(getVT(Sgn(CByte(1))) ="VT_I2", "getVT(Sgn(CByte(1))) = " & getVT(Sgn(CByte(1))))
|
||||
|
||||
Sub testSgnError(strings, error_num)
|
||||
on error resume next
|
||||
|
||||
Call Err.clear()
|
||||
Call Sgn(strings)
|
||||
Call ok(Err.number = error_num, "Err.number = " & Err.number)
|
||||
End Sub
|
||||
|
||||
Call testSgnError(Null, 94)
|
||||
|
||||
Call reportSuccess()
|
||||
|
|
|
@ -406,6 +406,7 @@ HRESULT map_hres(HRESULT) DECLSPEC_HIDDEN;
|
|||
#define VBSE_PERMISSION_DENIED 70
|
||||
#define VBSE_PATH_FILE_ACCESS 75
|
||||
#define VBSE_PATH_NOT_FOUND 76
|
||||
#define VBSE_ILLEGAL_NULL_USE 94
|
||||
#define VBSE_OLE_NOT_SUPPORTED 430
|
||||
#define VBSE_OLE_NO_PROP_OR_METHOD 438
|
||||
#define VBSE_ACTION_NOT_SUPPORTED 445
|
||||
|
|
Loading…
Reference in New Issue