mirror of
				https://github.com/eledio-devices/thirdparty-tinyexpr.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	extra test cases and general cleanup
This commit is contained in:
		
							
								
								
									
										1
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Makefile
									
									
									
									
									
								
							| @@ -1,3 +1,4 @@ | |||||||
|  | CC = gcc | ||||||
| CCFLAGS = -ansi -Wall -Wshadow -O2 | CCFLAGS = -ansi -Wall -Wshadow -O2 | ||||||
| LFLAGS = -lm | LFLAGS = -lm | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								benchmark.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								benchmark.c
									
									
									
									
									
								
							| @@ -96,6 +96,14 @@ double a5(double a) { | |||||||
|     return a+5; |     return a+5; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | double a55(double a) { | ||||||
|  |     return 5+a+5; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | double a5abs(double a) { | ||||||
|  |     return fabs(a+5); | ||||||
|  | } | ||||||
|  |  | ||||||
| double a52(double a) { | double a52(double a) { | ||||||
|     return (a+5)*2; |     return (a+5)*2; | ||||||
| } | } | ||||||
| @@ -115,8 +123,11 @@ double al(double a) { | |||||||
| int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|  |  | ||||||
|     bench("sqrt(a^1.5+a^2.5)", as); |  | ||||||
|     bench("a+5", a5); |     bench("a+5", a5); | ||||||
|  |     bench("5+a+5", a55); | ||||||
|  |     bench("abs(a+5)", a5abs); | ||||||
|  |  | ||||||
|  |     bench("sqrt(a^1.5+a^2.5)", as); | ||||||
|     bench("a+(5*2)", a10); |     bench("a+(5*2)", a10); | ||||||
|     bench("(a+5)*2", a52); |     bench("(a+5)*2", a52); | ||||||
|     bench("(1/(a+1)+2/(a+2)+3/(a+3))", al); |     bench("(1/(a+1)+2/(a+2)+3/(a+3))", al); | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								test.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								test.c
									
									
									
									
									
								
							| @@ -1,7 +1,7 @@ | |||||||
| /* | /* | ||||||
|  * TINYEXPR - Tiny recursive descent parser and evaluation engine in C |  * TINYEXPR - Tiny recursive descent parser and evaluation engine in C | ||||||
|  * |  * | ||||||
|  * Copyright (c) 2015, 2016 Lewis Van Winkle |  * Copyright (c) 2015-2020 Lewis Van Winkle | ||||||
|  * |  * | ||||||
|  * http://CodePlea.com |  * http://CodePlea.com | ||||||
|  * |  * | ||||||
| @@ -578,23 +578,36 @@ void test_pow() { | |||||||
|         {"-2^2", "-(2^2)"}, |         {"-2^2", "-(2^2)"}, | ||||||
|         {"--2^2", "(2^2)"}, |         {"--2^2", "(2^2)"}, | ||||||
|         {"---2^2", "-(2^2)"}, |         {"---2^2", "-(2^2)"}, | ||||||
|         {"-(2)^2", "-(2^2)"}, |  | ||||||
|         {"-(2*1)^2", "-(2^2)"}, |         {"-(2*1)^2", "-(2^2)"}, | ||||||
|         {"-2^2", "-4"}, |         {"-2^2", "-4"}, | ||||||
|         {"2^1.1^1.2^1.3", "2^(1.1^(1.2^1.3))"}, |         {"2^1.1^1.2^1.3", "2^(1.1^(1.2^1.3))"}, | ||||||
|         {"-a^b", "-(a^b)"}, |         {"-a^b", "-(a^b)"}, | ||||||
|         {"-a^-b", "-(a^-b)"} |         {"-a^-b", "-(a^-b)"}, | ||||||
|  |         {"1^0", "1"}, | ||||||
|  |         {"(1)^0", "1"}, | ||||||
|  |         {"-(2)^2", "-(2^2)"} | ||||||
|  |         /* TODO POW FROM RIGHT IS STILL BUGGY | ||||||
|  |         {"(-2)^2", "4"}, | ||||||
|  |         {"(-1)^0", "1"}, | ||||||
|  |         {"(-5)^0", "1"}, | ||||||
|  |         {"-2^-3^-4", "-(2^(-(3^-4)))"}*/ | ||||||
|     }; |     }; | ||||||
| #else | #else | ||||||
|     test_equ cases[] = { |     test_equ cases[] = { | ||||||
|         {"2^3^4", "(2^3)^4"}, |         {"2^3^4", "(2^3)^4"}, | ||||||
|         {"-2^2", "(-2)^2"}, |         {"-2^2", "(-2)^2"}, | ||||||
|  |         {"(-2)^2", "4"}, | ||||||
|         {"--2^2", "2^2"}, |         {"--2^2", "2^2"}, | ||||||
|         {"---2^2", "(-2)^2"}, |         {"---2^2", "(-2)^2"}, | ||||||
|         {"-2^2", "4"}, |         {"-2^2", "4"}, | ||||||
|         {"2^1.1^1.2^1.3", "((2^1.1)^1.2)^1.3"}, |         {"2^1.1^1.2^1.3", "((2^1.1)^1.2)^1.3"}, | ||||||
|         {"-a^b", "(-a)^b"}, |         {"-a^b", "(-a)^b"}, | ||||||
|         {"-a^-b", "(-a)^(-b)"} |         {"-a^-b", "(-a)^(-b)"}, | ||||||
|  |         {"1^0", "1"}, | ||||||
|  |         {"(1)^0", "1"}, | ||||||
|  |         {"(-1)^0", "1"}, | ||||||
|  |         {"(-5)^0", "1"}, | ||||||
|  |         {"-2^-3^-4", "((-2)^(-3))^(-4)"} | ||||||
|     }; |     }; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| @@ -620,7 +633,11 @@ void test_pow() { | |||||||
|         double r2 = te_eval(ex2); |         double r2 = te_eval(ex2); | ||||||
|  |  | ||||||
|         fflush(stdout); |         fflush(stdout); | ||||||
|  |         const int olfail = lfails; | ||||||
|         lfequal(r1, r2); |         lfequal(r1, r2); | ||||||
|  |         if (olfail != lfails) { | ||||||
|  |             printf("Failed expression: %s <> %s\n", expr1, expr2); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         te_free(ex1); |         te_free(ex1); | ||||||
|         te_free(ex2); |         te_free(ex2); | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| /* | /* | ||||||
|  * TINYEXPR - Tiny recursive descent parser and evaluation engine in C |  * TINYEXPR - Tiny recursive descent parser and evaluation engine in C | ||||||
|  * |  * | ||||||
|  * Copyright (c) 2015-2018 Lewis Van Winkle |  * Copyright (c) 2015-2020 Lewis Van Winkle | ||||||
|  * |  * | ||||||
|  * http://CodePlea.com |  * http://CodePlea.com | ||||||
|  * |  * | ||||||
| @@ -418,7 +418,6 @@ static te_expr *factor(state *s) { | |||||||
|     te_expr *ret = power(s); |     te_expr *ret = power(s); | ||||||
|  |  | ||||||
|     int neg = 0; |     int neg = 0; | ||||||
|     te_expr *insertion = 0; |  | ||||||
|  |  | ||||||
|     if (ret->type == (TE_FUNCTION1 | TE_FLAG_PURE) && ret->function == negate) { |     if (ret->type == (TE_FUNCTION1 | TE_FLAG_PURE) && ret->function == negate) { | ||||||
|         te_expr *se = ret->parameters[0]; |         te_expr *se = ret->parameters[0]; | ||||||
| @@ -427,6 +426,8 @@ static te_expr *factor(state *s) { | |||||||
|         neg = 1; |         neg = 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     te_expr *insertion = 0; | ||||||
|  |  | ||||||
|     while (s->type == TOK_INFIX && (s->function == pow)) { |     while (s->type == TOK_INFIX && (s->function == pow)) { | ||||||
|         te_fun2 t = s->function; |         te_fun2 t = s->function; | ||||||
|         next_token(s); |         next_token(s); | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| /* | /* | ||||||
|  * TINYEXPR - Tiny recursive descent parser and evaluation engine in C |  * TINYEXPR - Tiny recursive descent parser and evaluation engine in C | ||||||
|  * |  * | ||||||
|  * Copyright (c) 2015-2018 Lewis Van Winkle |  * Copyright (c) 2015-2020 Lewis Van Winkle | ||||||
|  * |  * | ||||||
|  * http://CodePlea.com |  * http://CodePlea.com | ||||||
|  * |  * | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user