Merge pull request #1345 from melex750/dev-cbot-fix-abs
Fix abs() only working on floatspyro-refactor
commit
dbc13bad20
|
@ -144,13 +144,36 @@ bool rRand(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|||
|
||||
bool rAbs(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
float value;
|
||||
switch (result->GetType())
|
||||
{
|
||||
case CBotTypDouble:
|
||||
*result = fabs(var->GetValDouble());
|
||||
break;
|
||||
case CBotTypFloat:
|
||||
*result = fabs(var->GetValFloat());
|
||||
break;
|
||||
case CBotTypLong:
|
||||
*result = abs(var->GetValLong());
|
||||
break;
|
||||
default:
|
||||
*result = abs(var->GetValInt());
|
||||
break;
|
||||
}
|
||||
|
||||
value = var->GetValFloat();
|
||||
result->SetValFloat(fabs(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
CBotTypResult cAbs(CBotVar* &var, void* user)
|
||||
{
|
||||
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
||||
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
|
||||
CBotTypResult returnType(var->GetType());
|
||||
var = var->GetNext();
|
||||
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
||||
return returnType;
|
||||
}
|
||||
|
||||
// Instruction "floor()"
|
||||
|
||||
bool rFloor(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
|
@ -209,7 +232,7 @@ void InitMathFunctions()
|
|||
CBotProgram::AddFunction("sqrt", rSqrt, cOneFloat);
|
||||
CBotProgram::AddFunction("pow", rPow, cTwoFloat);
|
||||
CBotProgram::AddFunction("rand", rRand, cNull);
|
||||
CBotProgram::AddFunction("abs", rAbs, cOneFloat);
|
||||
CBotProgram::AddFunction("abs", rAbs, cAbs);
|
||||
CBotProgram::AddFunction("floor", rFloor, cOneFloat);
|
||||
CBotProgram::AddFunction("ceil", rCeil, cOneFloat);
|
||||
CBotProgram::AddFunction("round", rRound, cOneFloat);
|
||||
|
|
Loading…
Reference in New Issue