Fix unary - on fps

floating-point
Nicolas Hake 2011-01-06 21:03:31 +01:00
parent 3a280bcb4f
commit 3af311d675
2 changed files with 21 additions and 3 deletions

View File

@ -281,7 +281,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
break;
case AB_Neg: // -
CheckOpPar(pCPos->Par.i);
pCurVal->SetInt(-pCurVal->_getInt());
pCurVal->Set(-*pCurVal);
break;
case AB_Inc: // ++
CheckOpPar(pCPos->Par.i);

View File

@ -186,6 +186,7 @@ public:
{
switch (Type)
{
case C4V_Any:
case C4V_Int:
case C4V_Bool:
++Data.Int; Type = C4V_Int; break;
@ -206,6 +207,7 @@ public:
{
switch (Type)
{
case C4V_Any:
case C4V_Int:
case C4V_Bool:
--Data.Int; Type = C4V_Int; break;
@ -222,6 +224,24 @@ public:
operator--();
return nrv;
}
C4Value operator-() const
{
C4Value nrv;
nrv.Data.Int = Data.Int ^ 0x80000000;
switch (Type)
{
case C4V_Any:
case C4V_Int:
case C4V_Bool:
nrv.Type = C4V_Int; break;
case C4V_Float:
nrv.Type = C4V_Float; break;
default:
assert(!"Can't negate a non-numeric value");
return *this;
}
return nrv;
}
C4Value Pow(const C4Value &rhs) const
{
assert(ConvertTo(C4V_Numeric));
@ -265,8 +285,6 @@ public:
}
inline static bool WarnAboutConversion(C4V_Type vtFromType, C4V_Type vtToType)
{
assert(vtFromType <= C4V_Last);
assert(vtToType <= C4V_Last);
if (vtFromType > C4V_Last || vtToType > C4V_Last)
return false;
return C4ScriptCnvMap[vtFromType][vtToType].Warn;