From 66626c7f79f1d1a07847b5d9de5591412d047603 Mon Sep 17 00:00:00 2001 From: mekolat Date: Tue, 18 Aug 2015 16:13:52 -0400 Subject: add builtins sqrt, cbrt, pow --- src/map/script-fun.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/map/script-fun.cpp') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 496cc91..f85a181 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -310,6 +310,24 @@ void builtin_rand(ScriptState *st) } } +static +void builtin_sqrt(ScriptState *st) +{ + push_int(st->stack, static_cast(sqrt(conv_num(st, &AARG(0))))); +} + +static +void builtin_cbrt(ScriptState *st) +{ + push_int(st->stack, static_cast(cbrt(conv_num(st, &AARG(0))))); +} + +static +void builtin_pow(ScriptState *st) +{ + push_int(st->stack, static_cast(pow(conv_num(st, &AARG(0)), conv_num(st, &AARG(1))))); +} + /*========================================== * Check whether the PC is at the specified location *------------------------------------------ @@ -3369,6 +3387,9 @@ BuiltinFunction builtin_functions[] = BUILTIN(mapexit, ""_s, '\0'), BUILTIN(freeloop, "i"_s, '\0'), BUILTIN(if_then_else, "iii"_s, '.'), + BUILTIN(sqrt, "i"_s, 'i'), + BUILTIN(cbrt, "i"_s, 'i'), + BUILTIN(pow, "ii"_s, 'i'), {nullptr, ""_s, ""_s, '\0'}, }; } // namespace map -- cgit v1.2.3-60-g2f50