mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix floating point numerics having precision of 0 with assignments (#149)
Issuing typeset floating point numerics having a precision of 0 failed as the precision/size was being overwritten with the string length of the value, e.g. 'typeset -F0 x=5.67' would result in 'typeset -F 4 x=5.6700' as len('5.67') is 4. src/cmd/ksh93/include/nval.h: - Created a symbolic name of NV_FLTSIZEZERO to respresent a float having a precision/size of 0. NV_FLTSIZEZERO needs to be a negative value. src/cmd/ksh93/bltins/typeset.c: - In b_typeset(), added code to set tdata.argnum to NV_FLTSIZEZERO for E, F, X options. - In setall(), adjusted code to allow for tp->argnum to be negative. src/cmd/ksh93/sh/name.c: nv_newattr(): - Adjusted option value only change code to handle NV_FLTSIZEZERO as well as changed to directly setting np->nvsize instead of using nv_setsize(np,size) as nv_setsize might contain conflicting and/or redundant code. - Added missing conditional check of '!(newatts&NV_INTEGER)' to constrain the size==0 code block to justified strings as NV_LJUST, NV_RJUST, or NV_ZFILL are only valid for strings if NV_INTEGER is not set. This code block was mistakenly setting the precision/size value to the length of the value of an assignment for floats whereas it should only be performing auto assignment length for justified strings.
This commit is contained in:
parent
95fe07d869
commit
88a6baa1a7
6 changed files with 27 additions and 5 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue