mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +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:
parent
c7aa644390
commit
3a99ef322d
4 changed files with 30 additions and 4 deletions
|
@ -1,5 +1,9 @@
|
||||||
2015-01-15 Peter Stephenson <p.stephenson@samsung.com>
|
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:
|
* 34287 (see 34286 from Markus Trippelsdorf): Src/zsh.mdd:
|
||||||
use -E argument for generating signal names if gcc is
|
use -E argument for generating signal names if gcc is
|
||||||
preprocessor.
|
preprocessor.
|
||||||
|
|
|
@ -496,9 +496,10 @@ pindex(NOFORCEFLOAT)
|
||||||
cindex(floating point, forcing use of)
|
cindex(floating point, forcing use of)
|
||||||
cindex(forcing use of floating point)
|
cindex(forcing use of floating point)
|
||||||
item(tt(FORCE_FLOAT))(
|
item(tt(FORCE_FLOAT))(
|
||||||
Constants in arithmetic evaluation will be treated as floating point
|
Constants in arithmetic evaluation will be treated as
|
||||||
even without the use of a decimal point. Integers in any base
|
floating point even without the use of a decimal point; the
|
||||||
will be converted.
|
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(GLOB)
|
||||||
pindex(NO_GLOB)
|
pindex(NO_GLOB)
|
||||||
|
|
13
Src/math.c
13
Src/math.c
|
@ -336,16 +336,27 @@ enum prec_type {
|
||||||
static mnumber
|
static mnumber
|
||||||
getmathparam(struct mathvalue *mptr)
|
getmathparam(struct mathvalue *mptr)
|
||||||
{
|
{
|
||||||
|
mnumber result;
|
||||||
if (!mptr->pval) {
|
if (!mptr->pval) {
|
||||||
char *s = mptr->lval;
|
char *s = mptr->lval;
|
||||||
mptr->pval = (Value)zhalloc(sizeof(struct value));
|
mptr->pval = (Value)zhalloc(sizeof(struct value));
|
||||||
if (!getvalue(mptr->pval, &s, 1))
|
if (!getvalue(mptr->pval, &s, 1))
|
||||||
{
|
{
|
||||||
mptr->pval = NULL;
|
mptr->pval = NULL;
|
||||||
|
if (isset(FORCEFLOAT)) {
|
||||||
|
result.type = MN_FLOAT;
|
||||||
|
result.u.d = 0.0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return zero_mnumber;
|
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
|
static mnumber
|
||||||
|
|
|
@ -308,3 +308,13 @@
|
||||||
>2
|
>2
|
||||||
>2
|
>2
|
||||||
# It's hard to test for integer to float.
|
# 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
|
||||||
|
|
Loading…
Reference in a new issue