mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 03:02:06 +00:00
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:
@@ -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 == '*') {
|
||||
|
||||
Reference in New Issue
Block a user