Unary minus of a constant does make the number signed.
It is wrong to assume that the result of a unary minus is signed. Doing so can cause incorrect results in subsequent math.
This commit is contained in:
parent
8e1f22cd82
commit
a1495bb007
|
|
@ -1866,16 +1866,15 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope,
|
||||||
if (expr_wid > 0)
|
if (expr_wid > 0)
|
||||||
val = pad_to_width(val, expr_wid);
|
val = pad_to_width(val, expr_wid);
|
||||||
|
|
||||||
/* When taking the - of a number, turn it into a
|
/* When taking the - of a number, extend it one
|
||||||
signed expression and extend it one bit to
|
bit to accommodate a possible sign bit. */
|
||||||
accommodate a possible sign bit. */
|
|
||||||
verinum zero (verinum::V0, val.len()+1, val.has_len());
|
verinum zero (verinum::V0, val.len()+1, val.has_len());
|
||||||
zero.has_sign(val.has_sign());
|
zero.has_sign(val.has_sign());
|
||||||
verinum nval = zero - val;
|
verinum nval = zero - val;
|
||||||
|
|
||||||
if (val.has_len())
|
if (val.has_len())
|
||||||
nval = verinum(nval, val.len());
|
nval = verinum(nval, val.len());
|
||||||
nval.has_sign(true);
|
nval.has_sign(val.has_sign());
|
||||||
tmp = new NetEConst(nval);
|
tmp = new NetEConst(nval);
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
delete ip;
|
delete ip;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue