From dcb010fdfbc7dac48197d71a504a0ab71878c03c Mon Sep 17 00:00:00 2001 From: Henry Rich Date: Sat, 11 Jan 2025 14:32:26 -0500 Subject: [PATCH] '-' sign in ":!.20 qp; leading - sign lost from _0.1fq; crash in 0j_1 ": 0fq --- jsrc/f.c | 3 ++- jsrc/f2.c | 7 ++++++- jsrc/wn.c | 7 +++---- test/gj.ijs | 13 +++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/jsrc/f.c b/jsrc/f.c index 3d5bd8b6c..93f1ddd77 100644 --- a/jsrc/f.c +++ b/jsrc/f.c @@ -147,6 +147,7 @@ struct fmtbuf fmtlong(struct fmtbuf fb, E v){ finish:; if(ndig!=0&&buf[0]==0){++buf; --dp; --ndig;} // if we added a lead 0 and it is still there, remove it DO(ndig, buf[i]+='0';) // convert the digits to chars + dp=ndig==0?1:dp; // if there are no digits, input must be 0; set decimal point to 1 to match 0. display R (struct fmtbuf){buf,fbuf,ndig,dp}; } @@ -161,7 +162,7 @@ static FMTF(jtfmtE,E){UI i; // copy result to output area I endx0=MIN(r.ndig,jt->ppn); // discard excess significance I exp0=r.dp; // number of digits of sig before decimal point. Can be neg - s[0]='-'; I sgn0=v->hi<0; // install - sign just in case; set sgn0 to be # chars of sign needed + s[0]='_'; I sgn0=v->hi<0; // install - sign just in case; set sgn0 to be # chars of sign needed if(BETWEENC(exp0,0,endx0)){ // decimal point within significance: report as decimal if(exp0==0)s[sgn0++]='0'; // if no digits before decimal point, add one and add it to count of sign chars diff --git a/jsrc/f2.c b/jsrc/f2.c index 3c59006e6..612f46990 100644 --- a/jsrc/f2.c +++ b/jsrc/f2.c @@ -215,7 +215,12 @@ static B jtfmte(J jt,B e,I m,I d,C*s,I t,E*wv,A*cellbuf){ C *z=CAV(*cellbuf); // place to build result, which is known to fit z[0]=' '; z+=s[0]==' '; z[0]='_'; z+=wv->hi<0; // advance s past optional leading space and sign if(e){ // %e field, scientific - *z++=fmt.buf[0]; if(wdec){*z++='.'; I nfrac=MIN(fmt.ndig-1,wfrac); MC(z,&fmt.buf[1],nfrac); if(unlikely(nfrac0){MC(z,&fmt.buf[0],fmt.dp); z+=fmt.dp;}else *z++='0'; // if there are integer digits, move them; if not lead with 0. Advance z to frac diff --git a/jsrc/wn.c b/jsrc/wn.c index fe501e18b..028178792 100644 --- a/jsrc/wn.c +++ b/jsrc/wn.c @@ -84,15 +84,14 @@ static NUMH(jtnumfq){E *v;D sgn=1.0; else if(ihi=v->lo=0*sgn;R 1;} + if(unlikely(ex<-400)){v->hi=v->lo=0*sgn;R 1;} // underflow RZ(qquad(v,qtymes(((Q){.n=r,.d=X1}),((Q){.n=X1,.d=xpow(xc(10),xc(-ex))}))));} else{ if(ex){ - // overflow - if(unlikely(ex>400)){v->hi=inf*sgn;R 1;} + if(unlikely(ex>400)){v->hi=inf*sgn;R 1;}// overflow r=xtymes(r,xpow(xc(10),xc(ex)));} RZ(xquad(v,r));} + v->hi*=sgn; v->lo*=sgn; // install sign, which does not upset canonical form R 1;} static NUMH(jtnumj){C*t,*ta;D x,y;Z*v; diff --git a/test/gj.ijs b/test/gj.ijs index f12aee4d8..516b84619 100644 --- a/test/gj.ijs +++ b/test/gj.ijs @@ -268,6 +268,19 @@ a =: 1 +&(11&c.) 1e_20 '1.000000000000000000000000000000' -: 0j30 ": (*%) 11 c. 665142606648569600281099799288x +'1.000000000000000039' -: ":!.20[1.00000000000000004fq +(,'1') -: ":[1.00000000000000004fq +'_1.000000000000000039' -: ":!.20[_1.00000000000000004fq +(,'_1') -: ":[_1.00000000000000004fq +(,'_3.99999999999999991e_17') -: ":!.20[_0.00000000000000004fq +('3.99999999999999991e_17') -: ":!.20[0.00000000000000004fq + +'0.0e0' -: 0j_1 ": 0fq +'0.00e0' -: 0j_2 ": 0fq +'5.00e_1' -: 0j_2 ": 0.5fq +'_5.00e_1' -: 0j_2 ": _0.5fq + + NB. qx =: 11 c. 665142606648569600281099799288x NB. qy =: 11 c. 665142606648569600281099799280x NB. t =: 9!:12