Update mathematical functions (#675)

Document the existing `ROUND`, `CEIL`, and `FLOOR` functions
Also update the trig function docs for searchability

Implement `POW` and `LOG`
Addresses part of #675

Implement ** for integer exponents
** has higher precedence than -, like Python, so -3**4 == -(3**4) == 81
This commit is contained in:
Rangi
2021-01-01 19:39:20 -05:00
committed by GitHub
parent 7bb6f71f0b
commit 895ec5564d
11 changed files with 148 additions and 12 deletions

View File

@@ -182,6 +182,8 @@ static struct KeywordMapping {
{"FLOOR", T_OP_FLOOR},
{"DIV", T_OP_FDIV},
{"MUL", T_OP_FMUL},
{"POW", T_OP_POW},
{"LOG", T_OP_LOG},
{"SIN", T_OP_SIN},
{"COS", T_OP_COS},
{"TAN", T_OP_TAN},
@@ -488,7 +490,7 @@ struct KeywordDictNode {
uint16_t children[0x60 - ' '];
struct KeywordMapping const *keyword;
/* Since the keyword structure is invariant, the min number of nodes is known at compile time */
} keywordDict[350] = {0}; /* Make sure to keep this correct when adding keywords! */
} keywordDict[352] = {0}; /* Make sure to keep this correct when adding keywords! */
/* Convert a char into its index into the dict */
static inline uint8_t dictIndex(char c)
@@ -1606,13 +1608,20 @@ static int yylex_NORMAL(void)
lexer_GetLineNo(), lexer_GetColNo());
for (;;) {
int c = nextChar();
char secondChar;
switch (c) {
/* Ignore whitespace and comments */
case '*':
if (!lexerState->atLineStart)
if (!lexerState->atLineStart) { /* Either MUL or EXP */
secondChar = peek(0);
if (secondChar == '*') {
shiftChars(1);
return T_OP_EXP;
}
return T_OP_MUL;
}
warning(WARNING_OBSOLETE,
"'*' is deprecated for comments, please use ';' instead\n");
/* fallthrough */
@@ -1651,7 +1660,6 @@ static int yylex_NORMAL(void)
return T_COMMA;
/* Handle ambiguous 1- or 2-char tokens */
char secondChar;
case '/': /* Either division or a block comment */
secondChar = peek(0);
if (secondChar == '*') {