Skip to content

Commit

Permalink
libdeng2|scriptsys: Added built-in function "floor"
Browse files Browse the repository at this point in the history
Rounding a number down to an integer.
  • Loading branch information
skyjake committed May 12, 2013
1 parent db75647 commit 9659f9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doomsday/libdeng2/include/de/scriptsys/builtinexpression.h
Expand Up @@ -53,7 +53,8 @@ class BuiltInExpression : public Expression
DESERIALIZE = 10,
AS_TIME = 11,
TIME_DELTA = 12,
AS_RECORD = 13
AS_RECORD = 13,
FLOOR = 14
};

public:
Expand Down
10 changes: 10 additions & 0 deletions doomsday/libdeng2/src/scriptsys/builtinexpression.cpp
Expand Up @@ -29,6 +29,7 @@
#include "de/TimeValue"
#include "de/Writer"
#include "de/Reader"
#include "de/math.h"

using namespace de;

Expand Down Expand Up @@ -262,6 +263,14 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const
"deserialize() can operate only on block values");
}

case FLOOR:
if(args->size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for FLOOR");
}
return new NumberValue(std::floor(args->at(1).asNumber()));

default:
DENG2_ASSERT(false);
}
Expand Down Expand Up @@ -317,6 +326,7 @@ BuiltInExpression::Type BuiltInExpression::findType(String const &identifier)
{ "Time", AS_TIME },
{ "timedelta", TIME_DELTA },
{ "Record", AS_RECORD },
{ "floor", FLOOR },
{ NULL, NONE }
};

Expand Down

0 comments on commit 9659f9d

Please sign in to comment.