mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 04:37:47 +08:00
Log and Round Functions (#154)
* Added log and round functions to math module * Added log and round functions to math module
This commit is contained in:
parent
f1bbafaa28
commit
b35b7a48cc
@ -701,6 +701,7 @@ DEF(coreStrOrd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// List functions.
|
// List functions.
|
||||||
// ---------------
|
// ---------------
|
||||||
|
|
||||||
@ -1041,6 +1042,22 @@ DEF(stdMathArcTangent,
|
|||||||
RET(VAR_NUM(atan(num)));
|
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.
|
// 'Fiber' module methods.
|
||||||
// -----------------------
|
// -----------------------
|
||||||
|
|
||||||
@ -1184,6 +1201,8 @@ void initializeCore(PKVM* vm) {
|
|||||||
MODULE_ADD_FN(math, "asin", stdMathArcSine, 1);
|
MODULE_ADD_FN(math, "asin", stdMathArcSine, 1);
|
||||||
MODULE_ADD_FN(math, "acos", stdMathArcCosine, 1);
|
MODULE_ADD_FN(math, "acos", stdMathArcCosine, 1);
|
||||||
MODULE_ADD_FN(math, "atan", stdMathArcTangent, 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
|
// 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
|
// constant and pocketlang doesn't support constant) so the user shouldn't
|
||||||
|
Loading…
Reference in New Issue
Block a user