--- ray/src/cal/tabfunc.c 2020/06/29 21:25:36 1.9 +++ ray/src/cal/tabfunc.c 2024/02/28 03:17:23 1.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tabfunc.c,v 1.9 2020/06/29 21:25:36 greg Exp $"; +static const char RCSid[] = "$Id: tabfunc.c,v 1.11 2024/02/28 03:17:23 greg Exp $"; #endif /* * Put tabular data into functions suitable for cal programs. @@ -106,7 +106,7 @@ FILE *fp goto fatal; } ordinate[i][tabsize] = atof(cp); - if ((cp = fskip(cp)) == NULL) { + if ((cp = fskip(cp)) == NULL || !isdelim(*cp)) { err = "bad floating-point format"; goto fatal; } @@ -156,20 +156,21 @@ absc_exp(void) /* produce expression for abscissa */ printf("X`%s(i):select(i,", locID); putlist(abscissa, tabsize, 20); puts(");"); - if (increasing) { + if (increasing) printf("fx2`%s(x,i):if(x-X`%s(i),\n", locID, locID); + else + printf("fx2`%s(x,i):if(X`%s(i)-x,\n", locID, locID); + printf("\ti+(x-X`%s(i))/(X`%s(i+1)-X`%s(i)),\n", + locID, locID, locID); + printf("\tfx2`%s(x,i-1));\n", locID); + if (increasing) printf("fx`%s(x):if(x-%g,if(%g-x,fx2`%s(x,%d),%d),1);\n", locID, abscissa[0], abscissa[tabsize-1], locID, tabsize, tabsize); - } else { - printf("fx2`%s(x,i):if(X`%s(i)-x,\n", locID, locID); + else printf("fx`%s(x):if(%g-x,if(x-%g,fx2`%s(x,%d),%d),1);\n", locID, abscissa[0], abscissa[tabsize-1], locID, tabsize, tabsize); - } - printf("\ti+(x-X`%s(i))/(X`%s(i+1)-X`%s(i)),\n", - locID, locID, locID); - printf("\tfx2`%s(x,i-1));\n", locID); sprintf(ourexp, "fx`%s(x)", locID); } return(ourexp);