1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-04 10:41:11 +02:00

34280: more widespread use of FORCE_FLOAT.

Add the case of variables read for use in arithmetic expressions.
This commit is contained in:
Peter Stephenson 2015-01-15 13:52:08 +00:00
parent c7aa644390
commit 3a99ef322d
4 changed files with 30 additions and 4 deletions

View file

@ -1,5 +1,9 @@
2015-01-15 Peter Stephenson <p.stephenson@samsung.com>
* 34280: Doc/Zsh/options.yo, Src/math.c, Test/C01arith.ztst:
make FORCE_FLOAT option also cover variables when read for
use in arithmetic expressions.
* 34287 (see 34286 from Markus Trippelsdorf): Src/zsh.mdd:
use -E argument for generating signal names if gcc is
preprocessor.

View file

@ -496,9 +496,10 @@ pindex(NOFORCEFLOAT)
cindex(floating point, forcing use of)
cindex(forcing use of floating point)
item(tt(FORCE_FLOAT))(
Constants in arithmetic evaluation will be treated as floating point
even without the use of a decimal point. Integers in any base
will be converted.
Constants in arithmetic evaluation will be treated as
floating point even without the use of a decimal point; the
values of integer variables will be converted to floating point when
used in arithmetic expressions. Integers in any base will be converted.
)
pindex(GLOB)
pindex(NO_GLOB)

View file

@ -336,16 +336,27 @@ enum prec_type {
static mnumber
getmathparam(struct mathvalue *mptr)
{
mnumber result;
if (!mptr->pval) {
char *s = mptr->lval;
mptr->pval = (Value)zhalloc(sizeof(struct value));
if (!getvalue(mptr->pval, &s, 1))
{
mptr->pval = NULL;
if (isset(FORCEFLOAT)) {
result.type = MN_FLOAT;
result.u.d = 0.0;
return result;
}
return zero_mnumber;
}
}
return getnumvalue(mptr->pval);
result = getnumvalue(mptr->pval);
if (isset(FORCEFLOAT) && result.type == MN_INTEGER) {
result.type = MN_FLOAT;
result.u.d = (double)result.u.l;
}
return result;
}
static mnumber

View file

@ -308,3 +308,13 @@
>2
>2
# It's hard to test for integer to float.
integer ff1=3 ff2=4
print $(( ff1/ff2 ))
setopt force_float
print $(( ff1/ff2 ))
unsetopt force_float
0:Variables are forced to floating point where necessary
# 0.75 is exactly representable, don't expect rounding error.
>0
>0.75