mirror of
				https://github.com/eledio-devices/thirdparty-tinyexpr.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Changed the way POW_FROM_RIGHT works with negative constants.
This commit is contained in:
		
							
								
								
									
										6
									
								
								test.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								test.c
									
									
									
									
									
								
							| @@ -525,6 +525,10 @@ void test_pow() { | |||||||
| #ifdef TE_POW_FROM_RIGHT | #ifdef TE_POW_FROM_RIGHT | ||||||
|     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*1)^2", "-(2^2)"}, | ||||||
|  |         {"-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)"} | ||||||
| @@ -532,6 +536,8 @@ void test_pow() { | |||||||
| #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", "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)"} | ||||||
|   | |||||||
| @@ -384,12 +384,10 @@ static te_expr *factor(state *s) { | |||||||
|  |  | ||||||
|     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]; | ||||||
|         if (se->type != TE_CONSTANT) { |  | ||||||
|         free(ret); |         free(ret); | ||||||
|         ret = se; |         ret = se; | ||||||
|         neg = 1; |         neg = 1; | ||||||
|     } |     } | ||||||
|     } |  | ||||||
|  |  | ||||||
|     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; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user