vbscript: Round half to even in to_int.
Spotted by Zhan Jianyu.
This commit is contained in:
parent
7559526438
commit
48a8623062
|
@ -150,12 +150,20 @@ static HRESULT to_int(VARIANT *v, int *ret)
|
|||
*ret = V_I4(v);
|
||||
break;
|
||||
case VT_R8: {
|
||||
double n = round(V_R8(v));
|
||||
double n = floor(V_R8(v)+0.5);
|
||||
INT32 i;
|
||||
|
||||
if(!is_int32(n)) {
|
||||
FIXME("%lf is out of int range\n", n);
|
||||
return E_FAIL;
|
||||
}
|
||||
*ret = n;
|
||||
|
||||
/* Round half to even */
|
||||
i = n;
|
||||
if(i%2 && n-V_R8(v) == 0.5)
|
||||
i--;
|
||||
|
||||
*ret = i;
|
||||
break;
|
||||
}
|
||||
case VT_BOOL:
|
||||
|
|
|
@ -134,6 +134,8 @@ Call ok(getVT(Chr(120)) = "VT_BSTR", "getVT(Chr(120)) = " & getVT(Chr(120)))
|
|||
Call ok(getVT(Chr(255)) = "VT_BSTR", "getVT(Chr(255)) = " & getVT(Chr(255)))
|
||||
Call ok(Chr(120) = "x", "Chr(120) = " & Chr(120))
|
||||
Call ok(Chr(0) <> "", "Chr(0) = """"")
|
||||
Call ok(Chr(120.5) = "x", "Chr(120.5) = " & Chr(120.5))
|
||||
Call ok(Chr(119.5) = "x", "Chr(119.5) = " & Chr(119.5))
|
||||
|
||||
Call ok(isObject(new EmptyClass), "isObject(new EmptyClass) is not true?")
|
||||
Set x = new EmptyClass
|
||||
|
@ -292,6 +294,9 @@ Call ok(Space(5) = " ", "Space(5) = " & Space(5) & """")
|
|||
Call ok(Space(5.2) = " ", "Space(5.2) = " & Space(5.2) & """")
|
||||
Call ok(Space(5.8) = " ", "Space(5.8) = " & Space(5.8) & """")
|
||||
Call ok(Space(5.5) = " ", "Space(5.5) = " & Space(5.5) & """")
|
||||
Call ok(Space(4.5) = " ", "Space(4.5) = " & Space(4.5) & """")
|
||||
Call ok(Space(0.5) = "", "Space(0.5) = " & Space(0.5) & """")
|
||||
Call ok(Space(1.5) = " ", "Space(1.5) = " & Space(1.5) & """")
|
||||
|
||||
Sub TestStrReverse(str, ex)
|
||||
Call ok(StrReverse(str) = ex, "StrReverse(" & str & ") = " & StrReverse(str))
|
||||
|
@ -310,6 +315,8 @@ TestLeft "test", 2, "te"
|
|||
TestLeft "test", 5, "test"
|
||||
TestLeft "test", 0, ""
|
||||
TestLeft 123, 2, "12"
|
||||
TestLeft "123456", 1.5, "12"
|
||||
TestLeft "123456", 2.5, "12"
|
||||
if isEnglishLang then TestLeft true, 2, "Tr"
|
||||
|
||||
Sub TestRight(str, len, ex)
|
||||
|
@ -383,6 +390,8 @@ if isEnglishLang then
|
|||
Call ok(WeekDayName(1, 10) = "Sun", "WeekDayName(1, 10) = " & WeekDayName(1, 10))
|
||||
Call ok(WeekDayName(1, true, 0) = "Sun", "WeekDayName(1, true, 0) = " & WeekDayName(1, true, 0))
|
||||
Call ok(WeekDayName(1, true, 2) = "Mon", "WeekDayName(1, true, 2) = " & WeekDayName(1, true, 2))
|
||||
Call ok(WeekDayName(1, true, 2.5) = "Mon", "WeekDayName(1, true, 2.5) = " & WeekDayName(1, true, 2.5))
|
||||
Call ok(WeekDayName(1, true, 1.5) = "Mon", "WeekDayName(1, true, 1.5) = " & WeekDayName(1, true, 1.5))
|
||||
Call ok(WeekDayName(1, true, 7) = "Sat", "WeekDayName(1, true, 7) = " & WeekDayName(1, true, 7))
|
||||
Call ok(WeekDayName(1, true, 7.1) = "Sat", "WeekDayName(1, true, 7.1) = " & WeekDayName(1, true, 7.1))
|
||||
|
||||
|
|
Loading…
Reference in New Issue