SQLite Forum

Fail to calculate long expression
Login
After playing a bit with https://baturin.org/tools/bnfgen/ and creating a simplified text generator for a simple expression grammar I've got a long expression that PostgreSQL, Lua, Ruby, Python and Javascript can calculate but sqlite can't:

=====
select ( ((50.266))/2%((2816.31)/(996.7/8175.445-59.546)/((47))*((((93.614))+(((8*(19.6093/28))))))/(79.577-(178/82.7%(2020.26)-271.497%(7.495)*22.42/(892.4036)+((22)+(51.50-(((35%6062-25)-4.264))+5508/409.98)+(((((327.5845/(5296))-(6290.8)))%4+13.719)+146))*((((8877.8)+(5160)%3760-7058)%((62))))%93/(90.24%((993))+(9427)%303.97%(((((8))))/(((699))*(((25/1379.1))%9257.3-(5464+(30)-(7/((9.8))/3.655%9.3)))))-(27)%168-86-((((5.7326)))-((3412+(((11.8717))))*(75)+(899.1)*((541.7/595.1086+22.855+(9.8034+9.412)-(((7+322.7)))-7426*((18)-3782.5*67.144-2+((3.8)%((377)*8)/((56.9)))))))/((21)*664%(57.6974+9139.586+(((((336.4626))))+(((60-((((956)+(4.870+((5418))*(6/57)*(((1.4547+((457.1461)/((3066.6)*7156.5)+(3632)*((47.2*748%(((50.7320))))/(84.90))-6712.4084+(((2)))-69.11+(841+(22.6/925))%((492.43)*468)%93*(751)-(6%(12)%(((937.3850))*((11*((((6.410%7872))))*((5.1563/(7558%(8.16)+370+((((9064.16+4601%934.7722)%34.3146*2716.7-(42*((((21.67/(1115.3)%((68/((50.2))+(1.839*7))))))+639.1))/((8398.1)))%3222.93))%4655.2-28.19%((5896.9237%2/9987.49/((1*5)-(685)-2)%6-1+30.5884*839)))))%766%9681.9688*292.40+958.57*173%1426.305*(5.6*((8959)%57)*66/(((2.135))))*(((2661*43.8865+6.2-(5.87))))*(99.4726*23.254)+1+(((((1048/(60.87+(17)-8729)))/((8975))-762-855)))/(((((8168.14-82+(((10)*(((2762.1006))*(9094.95))-(733.7+(((694.5*83)-((85))*((7.2925)))))*30-((138))%330)))))))))-(((6082))+((6796))/85%1)))*(250))))/((3587.722)*(8-(16))-(503.2186)-((1))-((75.1284))%9984.3663*((875.1*43))-((((1)-28/((((9219.5261)))-3/111.874-((14.3*((566.57)+(932.3314))))*(63.8342)+568.681%(6)%(913)+(((156.28)+(9.7-(487.60))))%5514.738)%906.80))/3182+2.732-3307.9)*54%152-(((416.67-(22.7231)-5.2649)))*2))+8.1831+40.7/(99)-((((((((299.78/5.2*(3061.5-8451-((253.405+1-8.9*(((863.2/3202))-(4393*(44.1))/(8490)/(2-(22.535)*(((3.89)+4340.7750)))%6.2/204)/6653.5745/88+(3.8124)%952+(970.4977)%6438.6868/((9669.987)-15.8964)/(((7257)%(422.6)*(7.84-(2499.786))%(1)/9734.918%18/((((71)/(9606.6))%(7423/389.9548*(((3.98+3.3/((((((349)))))))%65)))))%(5402.73)*9.51*158.9-(524.26)%(3144)/(((1.300+4606+1.16/(6)))%(6.871+(2204))))-(2.7)%3014)))+8)+(6663)))%608.3)/4.404-(99)*520-568.526%5.9%11.811%61+(24)-((15+(25)-(5)*831+(((732)))%(9.226))*(851)/1.3%(1000*((449.360)+5055)-(332))-(396)-((310.809)))+(((7)-((50.9)/4325))-(38)+((297)+(5*9)/(8741-(((((27)-8843.11*(6/(((((908.3612))))+7-7+29)/3437.6*5166))-13.226)))/((((((21.5))))*(949.1150)%(((617%29%(((((1.5)/4560-7294/3078.7819*81+((7730))%1995/77.1%1156.44)-((4037*(1197.8/38.732)/(405.24+((479.1714%308.82)%2622.3+((7383.2244))-20.36*(6.31)%3336/9-4.643+5.909/66*(61.97)*6*(665.78)))*((9)))))/(6533)))*(13.9065)/38+(21))))-8.37-67.63))))+((((7)))*3150)*((812.7*((1.6*((64)))))+7656.380)%((((79.5592/(591))%(57%((48.8)-22/6.8))-7.444)%636%6/((6.68)*1)-(7.626/58.87)*(96%(8795*5585.1%7+1627.6/(6224)+6547%817*((3))/(((681.55)-494*(3.39)))*60)))))+9.26-(((54)))%((43.7689)/(6.4))/6103.18)-((9))/651.6%845.26))))-(5)+1%65/84.495+72.23-((((((634.1878)-293.77)+4))))/((67)))-411*(600))))-(2635))+370)))%(((4690.6))*((((3153.925%(832)))))/722+4830.750))*8564%9%(((88.6362*7924*(((((3727.652)))-79.9))/26)*67.360%(9888))))*53%(2203.7535)/7266+62.18/5.1894)-((((((7))%(((645.7678))))))*74))-4.51-460.4*825.986*5179.936-(9)*166*(927.8/90.45)-(56.1352)%567.47+((((10.4043*((31.7)+225.62-((3.8891*(1.4))))-8+((8532.7+(293.1/53.38/((1.1))+511.93+((93))-97%2035+3+(((3853.25)))+1000%(((((8.948)))*((1799.8993))-6.889*((((28.1))%1.3%17.1242-1846.940/4-(70)/((2.6%(((5.248)%(7841)))+1673%(5)%((((((1265)))*(814.7882)%7/1391+(33.875)/((7.5)))/92.96%(((533.1%(3035)/(((((4.6*(5832)+(72)-69.53*1)%((8))-((4))/64)))*95.46)-(335*4))))*(650))+(6)*70.520%6085.6723)-(61.91)/34-267*(45.3948-((8.2)))-(1/((10-243.770%262.83))%2.60%(55%6))%((745.82+((61.21)-27)-(52.2704)%8041-(((6)))%(7.181+9179)/25+143))+13+(96.297/84.21*((6879.4925)))%21%93.155+341.1+1230+(4)*(1.29)%((5829.8+(4)*4659.98*37))+(((7)))+6318.468*932/((75.8))/694+(3)%((19.9)/43/1846.887+3.5-(99.70)*4406+3615%(888.58+14/(7762%138.3/5642))/40.5-819-(73.2184)*(29.404-((3+5.129))%2489)%4874+5)-(1252)+(796.6401)-7.7461%((((127.3)))-7207+825.80)+((3756))%8770.816-((2.1911%4536.4))*(62.681)%9687.8*923.246+(94.834)-1164%(9)/(75.59)))%((960.4786)-4577.41)%9741.4/(4)-578.66-511/2+90.120))*345.3344+((4769.7))))%151))))))+98-32.1677-547/8)*5)-417%(962.3)/557.431%275+90)%(((2174.78)))-232-1-((233.40)%(4502)%(((7)))/415)) ) as expr;
=====

SQLite output:
=====

=====

PostgreSQL and Lua, Ruby, Javascript and Python:
=====
25.133
=====

Here is a simplified C generator:
=====
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

static int xrandom(int low, int up) {
	double r = (double)rand() * (1.0 / ((double)RAND_MAX + 1.0));
	r *= (double)(up - low) + 1.0;
	return ((int)r + low);
}


void expr_nzdigit() {
	switch(xrandom(1,9)) {
		case 1: printf("1"); break;
		case 2: printf("2"); break;
		case 3: printf("3"); break;
		case 4: printf("4"); break;
		case 5: printf("5"); break;
		case 6: printf("6"); break;
		case 7: printf("7"); break;
		case 8: printf("8"); break;
		case 9: printf("9"); break;
	}
}

void expr_digit() {
	switch(xrandom(0,9)) {
		case 0: printf("0"); break;
		case 1: printf("1"); break;
		case 2: printf("2"); break;
		case 3: printf("3"); break;
		case 4: printf("4"); break;
		case 5: printf("5"); break;
		case 6: printf("6"); break;
		case 7: printf("7"); break;
		case 8: printf("8"); break;
		case 9: printf("9"); break;
	}
}

void expr_integer() {
	expr_nzdigit();
	int imax = xrandom(0,3);
	for(int i=0; i < imax; ++i) expr_digit();
}

void expr_float() {
	expr_integer();
	printf(".");
	expr_integer();
}

void expr_number() {
	switch(xrandom(0,1)) {
		case 0: expr_integer(); break;
		case 1: expr_float(); break;
	}
}

void expr_operations() {
	switch(xrandom(0,4)) {
		case 0: printf("+"); break;
		case 1: printf("-"); break;
		case 2: printf("*"); break;
		case 3: printf("/"); break;
		case 4: printf("%%"); break;
	}
}

void expr_expr() {
	switch(xrandom(0,2)) {
		case 0: expr_expr(); expr_operations(); expr_expr(); break;
		case 1: printf("("); expr_expr(); printf(")"); break;
		case 2: expr_number(); break;
	}
}

void expr_start() {
	srand(clock());
	expr_expr();
	printf("\n");
}

int main(int argc, char *argv[]) {
	expr_start();
	return 0;
}
=====

For this grammar:
=====
<start> ::= <expr> ;

<expr> ::=
	<expr> <operations> <expr>
	| "(" <expr> ")"
	| <number>
	;

<operations> ::=
	"+" | "-" | "*" | "/" | "%"
	;

<nzdigit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
<digit> ::= "0" | <nzdigit> ;

<integer> ::= <nzdigit> <digit>{1, 3};
<float> ::= <nzdigit>{1, 3} "." <digit>{1, 3};
<number> ::= <integer> | <float>;
=====