diff --git a/NEWS b/NEWS index d43ad7f26..ff7a757dd 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2020-10-22: + +- Fixed: 'typeset -F0', 'typeset -E0', and 'typeset -X0' floating point + numerics having a precision of 0 with variable assignment. + 'typeset -F0 x; x=4.56' worked but not 'typeset -F0 x=4.56'. + 2020-10-21: - Fixed: More concisely correct the exporting of uppercase and lowercase diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 280b994bb..0dd9c8e84 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -262,6 +262,8 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) case 'X': if(!opt_info.arg || (tdata.argnum = opt_info.num) <0) tdata.argnum = (n=='X'?2*sizeof(Sfdouble_t):10); + else if (tdata.argnum==0) + tdata.argnum = NV_FLTSIZEZERO; isfloat = 1; if(n=='E') { @@ -797,7 +799,7 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp errormsg(SH_DICT,ERROR_exit(1),e_readonly,nv_name(np)); newflag = curflag & ~flag; } - if (tp->aflag && (tp->argnum>0 || (curflag!=newflag))) + if (tp->aflag && (tp->argnum || (curflag!=newflag))) { if(shp->subshell) sh_assignok(np,2); diff --git a/src/cmd/ksh93/include/nval.h b/src/cmd/ksh93/include/nval.h index 2a060e3f7..fe45d9553 100644 --- a/src/cmd/ksh93/include/nval.h +++ b/src/cmd/ksh93/include/nval.h @@ -165,6 +165,7 @@ struct Namval #define NV_DOUBLE (NV_INTEGER|NV_ZFILL) /* for floating point */ #define NV_EXPNOTE (NV_LJUST) /* for scientific notation */ #define NV_HEXFLOAT (NV_LTOU) /* for C99 base16 float notation */ +#define NV_FLTSIZEZERO -1 /* a float with size of 0 being <0 */ /* options for nv_open */ diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 1f4f74c00..cfef2eae7 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -17,4 +17,4 @@ * David Korn * * * ***********************************************************************/ -#define SH_RELEASE "93u+m 2020-10-21" +#define SH_RELEASE "93u+m 2020-10-22" diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 74f6cd6cc..e62e3408d 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -2963,12 +2963,16 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size) oldsize = nv_size(np); if((size==oldsize|| (n&NV_INTEGER)) && !trans && ((n^newatts)&~NV_NOCHANGE)==0) { - if(size) - nv_setsize(np,size); + if(size>0) + np->nvsize = size; + else if(size==NV_FLTSIZEZERO) + np->nvsize = 0; nv_offattr(np, ~NV_NOFREE); nv_onattr(np, newatts); return; } + if(size==NV_FLTSIZEZERO) + size = 0; /* for an array, change all the elements */ if((ap=nv_arrayptr(np)) && ap->nelem>0) nv_putsub(np,NIL(char*),ARRAY_SCAN); @@ -3019,7 +3023,7 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size) if(ap) ap->nelem |= ARRAY_SCAN; } - if(size==0 && (newatts&NV_HOST)!=NV_HOST && (newatts&(NV_LJUST|NV_RJUST|NV_ZFILL))) + if(size==0 && !(newatts&NV_INTEGER) && (newatts&NV_HOST)!=NV_HOST && (newatts&(NV_LJUST|NV_RJUST|NV_ZFILL))) size = n; } else if(!trans) diff --git a/src/cmd/ksh93/tests/math.sh b/src/cmd/ksh93/tests/math.sh index dd819e0f8..f2b304cc2 100755 --- a/src/cmd/ksh93/tests/math.sh +++ b/src/cmd/ksh93/tests/math.sh @@ -232,5 +232,14 @@ do tf=$i done unset i tf pf +unset x +[[ $(typeset -F 0 x=5.67; typeset -p x) == 'typeset -F 0 x=6' ]] || err_exit 'typeset -F 0 with assignment failed to round.' +[[ $(typeset -E 0 x=5.67; typeset -p x) == 'typeset -E 0 x=6' ]] || err_exit 'typeset -E 0 with assignment failed to round.' +[[ $(typeset -X 0 x=5.67; typeset -p x) == 'typeset -X 0 x=0x1p+2' ]] || err_exit 'typeset -X 0 with assignment failed to round.' + +[[ $(typeset -lF 0 x=5.67; typeset -p x) == 'typeset -l -F 0 x=6' ]] || err_exit 'typeset -lF 0 with assignment failed to round.' +[[ $(typeset -lE 0 x=5.67; typeset -p x) == 'typeset -l -E 0 x=6' ]] || err_exit 'typeset -lE 0 with assignment failed to round.' +[[ $(typeset -lX 0 x=5.67; typeset -p x) == 'typeset -l -X 0 x=0x1p+2' ]] || err_exit 'typeset -lX 0 with assignment failed to round.' + # ====== exit $((Errors<125?Errors:125))