From b35b7a48ccf4724b0522ac465a9e9893e3a835f1 Mon Sep 17 00:00:00 2001 From: Victor Akpan <67718730+victorakpan-dev@users.noreply.github.com> Date: Wed, 30 Jun 2021 07:25:25 +0100 Subject: [PATCH] Log and Round Functions (#154) * Added log and round functions to math module * Added log and round functions to math module --- src/pk_core.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pk_core.c b/src/pk_core.c index 4463989..8c79bef 100644 --- a/src/pk_core.c +++ b/src/pk_core.c @@ -701,6 +701,7 @@ DEF(coreStrOrd, } } + // List functions. // --------------- @@ -1041,6 +1042,22 @@ DEF(stdMathArcTangent, RET(VAR_NUM(atan(num))); } +DEF(stdMathLog10, + "log10(value:num) -> num\n" + "Return the logarithm to base 10 of argument [value]") { + double num; + if (!validateNumeric(vm, ARG(1), &num, "Argument 1")) return; + RET(VAR_NUM(log10(num))); +} + +DEF(stdMathRound, + "round(value:num) -> num\n" + ) { + double num; + if (!validateNumeric(vm, ARG(1), &num, "Argument 1")) return; + RET(VAR_NUM(round(num))); +} + // 'Fiber' module methods. // ----------------------- @@ -1184,6 +1201,8 @@ void initializeCore(PKVM* vm) { MODULE_ADD_FN(math, "asin", stdMathArcSine, 1); MODULE_ADD_FN(math, "acos", stdMathArcCosine, 1); MODULE_ADD_FN(math, "atan", stdMathArcTangent, 1); + MODULE_ADD_FN(math, "log10", stdMathLog10, 1); + MODULE_ADD_FN(math, "round", stdMathRound, 1); // Note that currently it's mutable (since it's a global variable, not // constant and pocketlang doesn't support constant) so the user shouldn't