mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
sfio: correct floating decimal point scaling of fractions (#131)
_sfcvt(), "convert a floating point value to ASCII", did not adjust for negative decimal place movement as what happens with leading zeroes. This caused ksh's 'printf %f' formatter to fail to round floating point values correctly. src/lib/libast/sfio/sfcvt.c: - Removed constraint of <1e-8 for doubles by matching what was done for long doubles having <.1. - Corrected a condition when the next power of 10 occurred and that new 1 digit was being overwritten by a 0. src/cmd/ksh93/tests/math.sh: - Validate that typeset -E/F formatting matches that of their equivalent printf formatting options as well as checking for correct float scaling of the fractional parts.
This commit is contained in:
parent
9f2066f146
commit
d7c90eadc3
4 changed files with 67 additions and 9 deletions
|
@ -193,4 +193,48 @@ function test_has_iszero
|
|||
test_arithmetric_expression_accesss_array_element_through_nameref
|
||||
test_has_iszero
|
||||
|
||||
# ======
|
||||
# Validate that typeset -E/F formatting matches that of their equivalent
|
||||
# printf formatting options as well as checking for correct float scaling
|
||||
# of the fractional parts.
|
||||
|
||||
unset i tf pf; typeset -F 3 tf
|
||||
for i in {'','-'}{0..1}.{0,9}{0,9}{0,1,9}{0,1,9}
|
||||
do tf=$i
|
||||
pf=${ printf '%.3f' tf ;}
|
||||
if [[ $tf != "$pf" ]]
|
||||
then err_exit "typeset -F formatted data does not match its printf. typeset -F 3: $tf != $pf"
|
||||
break
|
||||
fi
|
||||
done
|
||||
unset i tf pf; typeset -lF 3 tf
|
||||
for i in {'','-'}{0..1}.{0,9}{0,9}{0,1,9}{0,1,9}
|
||||
do tf=$i
|
||||
pf=${ printf '%.3Lf' tf ;}
|
||||
if [[ $tf != "$pf" ]]
|
||||
then err_exit "typeset -lF formatted data does not match its printf. typeset -lF 3: $tf != $pf"
|
||||
break
|
||||
fi
|
||||
done
|
||||
unset i tf pf; typeset -E 3 tf
|
||||
for i in {'','-'}{0..1}.{0,9}{0,9}{0,1,9}{0,1,9}
|
||||
do tf=$i
|
||||
pf=${ printf '%.3g' tf ;}
|
||||
if [[ $tf != "$pf" ]]
|
||||
then err_exit "typeset -E formatted data does not match its printf. typeset -E 3: $tf != $pf"
|
||||
break
|
||||
fi
|
||||
done
|
||||
unset i tf pf; typeset -lE 3 tf
|
||||
for i in {'','-'}{0..1}.{0,9}{0,9}{0,1,9}{0,1,9}
|
||||
do tf=$i
|
||||
pf=${ printf '%.3Lg' tf ;}
|
||||
if [[ $tf != "$pf" ]]
|
||||
then err_exit "typeset -lE formatted data does not match its printf. typeset -lE 3: $tf != $pf"
|
||||
break
|
||||
fi
|
||||
done
|
||||
unset i tf pf
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue