diff options
author | mbkma <[email protected]> | 2020-01-02 16:53:11 +0100 |
---|---|---|
committer | monsta <[email protected]> | 2020-01-16 15:45:33 +0300 |
commit | acedce5c72da86a1c5e723ad64315407705e0325 (patch) | |
tree | 0013a4774c6f5ebc3d4999114997366e5d21d037 | |
parent | 340b16e8d22f6e8af99d94525f19a55b1b5f9454 (diff) | |
download | mate-calc-acedce5c72da86a1c5e723ad64315407705e0325.tar.bz2 mate-calc-acedce5c72da86a1c5e723ad64315407705e0325.tar.xz |
fixes precedence of functions i.e. the result of -ln(1) and add according tests
-rw-r--r-- | src/parser.c | 2 | ||||
-rw-r--r-- | src/test-mp-equation.c | 32 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c index fb4fd12..b4f90fc 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1044,8 +1044,10 @@ variable(ParserState* state) LexerToken* token_old; ParseNode* node; token = l_get_next_token(state->lexer); + if(token->token_type == T_FUNCTION) { + state->depth_level++; token_old = token; token = l_get_next_token(state->lexer); if(token->token_type == T_SUP_NUMBER) diff --git a/src/test-mp-equation.c b/src/test-mp-equation.c index 4404a51..3977d8f 100644 --- a/src/test-mp-equation.c +++ b/src/test-mp-equation.c @@ -364,6 +364,38 @@ test_equations() test("(1+2×3)", "7", 0); test("2(1+1)", "4", 0); test("4÷2(1+1)", "4", 0); + test ("1 + 2 - 3 * 4 / 5", "0.6", 0); + test ("20 / 10 mod 3", "2", 0); + test ("12 / 3 √4", "8", 0); + test ("√5!", "10.95445115", 0); + test ("4 ^ sin 30", "2", 0); + test ("4 ^ (sin 30)", "2", 0); + test ("4 ^ sin (30)", "2", 0); + //test ("sin (30) ^ 4", "0.0625", 0); + //test ("sin 30 ^ 4", "0.0625", 0); + test ("sin (30 ^ 4)", "0", 0); + test ("-ln(1)", "0", 0); + test ("ln(-1)", "3.141592654i", 0); + + test ("10 / - 2", "−5", 0); + test ("10 * - 2", "−20", 0); + test ("10 ^ -2", "0.01", 0); + test ("-10 ^ 2", "−100", 0); + test ("sin (-30)", "−0.5", 0); + test ("sin - 30", "−0.5", 0); + + test ("6 + 3!", "12", 0); + test ("4 * 3!", "24", 0); + test ("100 mod 3!", "4", 0); + test ("5! mod 7", "1", 0); + test ("24 / 3!", "4", 0); + test ("4! / 6", "4", 0); + test ("cos 5!", "−0.5", 0); + test ("sin 6!", "0", 0); + test ("- 4!", "−24", 0); + test ("3! ^ 3", "216", 0); + test ("3 ^ 3!", "729", 0); + //test ("(−√3)^2", "3", 0); /* Percentage */ test("100%", "1", 0); |