aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2014-01-04 12:56:14 +0800
committerThomas Preud'homme <robotux@celest.fr>2014-01-04 17:07:58 +0800
commit3eed3506b4bf5b31eca4001d43d211a20c2376f1 (patch)
treebe13d8201d6a36ac8117e2b90f7c8127a02d914f /tccgen.c
parent0382131c6fc7510f664f300ee74d5a97e93d773d (diff)
downloadtinycc-3eed3506b4bf5b31eca4001d43d211a20c2376f1.tar.gz
tinycc-3eed3506b4bf5b31eca4001d43d211a20c2376f1.tar.bz2
Fix negation of 0.0 and -0.0
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/tccgen.c b/tccgen.c
index bf208af..e8f7f82 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -3794,9 +3794,22 @@ ST_FUNC void unary(void)
break;
case '-':
next();
- vpushi(0);
unary();
- gen_op('-');
+ t = vtop->type.t & VT_BTYPE;
+ /* handle (-)0.0 */
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST &&
+ is_float(t)) {
+ if (t == VT_FLOAT)
+ vtop->c.f = -vtop->c.f;
+ else if (t == VT_DOUBLE)
+ vtop->c.d = -vtop->c.d;
+ else
+ vtop->c.ld = -vtop->c.ld;
+ } else {
+ vpushi(0);
+ vswap();
+ gen_op('-');
+ }
break;
case TOK_LAND:
if (!gnu_ext)