mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-25 14:20:53 +01:00
Propagate float/integer type in arithmetic assignment.
Add test. Mention this and also floating point mod change in README.
This commit is contained in:
parent
626650f20e
commit
5f4325a0a4
4 changed files with 88 additions and 2 deletions
29
Src/math.c
29
Src/math.c
|
|
@ -880,6 +880,8 @@ getcvar(char *s)
|
|||
static mnumber
|
||||
setmathvar(struct mathvalue *mvp, mnumber v)
|
||||
{
|
||||
Param pm;
|
||||
|
||||
if (mvp->pval) {
|
||||
/*
|
||||
* This value may have been hanging around for a while.
|
||||
|
|
@ -909,7 +911,32 @@ setmathvar(struct mathvalue *mvp, mnumber v)
|
|||
if (noeval)
|
||||
return v;
|
||||
untokenize(mvp->lval);
|
||||
setnparam(mvp->lval, v);
|
||||
pm = setnparam(mvp->lval, v);
|
||||
if (pm) {
|
||||
/*
|
||||
* If we are performing an assignment, we return the
|
||||
* number with the same type as the parameter we are
|
||||
* assigning to, in the spirit of the way assignments
|
||||
* in C work. Note this was a change to long-standing
|
||||
* zsh behaviour.
|
||||
*/
|
||||
switch (PM_TYPE(pm->node.flags)) {
|
||||
case PM_INTEGER:
|
||||
if (v.type != MN_INTEGER) {
|
||||
v.u.l = (zlong)v.u.d;
|
||||
v.type = MN_INTEGER;
|
||||
}
|
||||
break;
|
||||
|
||||
case PM_EFLOAT:
|
||||
case PM_FFLOAT:
|
||||
if (v.type != MN_FLOAT) {
|
||||
v.u.d = (double)v.u.l;
|
||||
v.type = MN_FLOAT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue