Skip to content

Commit ffb1ac0

Browse files
committed
Fix '-0 m'
1 parent c384693 commit ffb1ac0

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

unitparse.tab.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ static const yytype_uint8 yytranslate[] =
482482
static const yytype_uint8 yyrline[] =
483483
{
484484
0, 49, 49, 55, 58, 62, 67, 78, 82, 86,
485-
91, 95, 99, 107, 112, 113, 119, 120, 125, 126,
486-
127, 131, 132
485+
92, 96, 100, 108, 113, 114, 120, 121, 126, 127,
486+
128, 132, 133
487487
};
488488
#endif
489489

@@ -1347,81 +1347,82 @@ yyparse (void)
13471347
#line 86 "unitparse.y" /* yacc.c:1646 */
13481348
{
13491349
unit_mult_internal(&(*(UnitShift*)(&yyvsp[-1])).unit, &(*(UnitShift*)(&yyvsp[0])).unit, &(*(UnitShift*)(&yyval)).unit);
1350-
(*(UnitShift*)(&yyval)).unit.value += (*(UnitShift*)(&yyvsp[0])).shift; /* shift is evaluated exactly here */
1350+
if ((*(UnitShift*)(&yyvsp[0])).shift != 0.0) /* avoid shift to not destroy -0 */
1351+
(*(UnitShift*)(&yyval)).unit.value += (*(UnitShift*)(&yyvsp[0])).shift; /* shift is evaluated exactly here */
13511352
(*(UnitShift*)(&yyval)).shift = 0.0;
13521353
}
1353-
#line 1354 "unitparse.tab.c" /* yacc.c:1646 */
1354+
#line 1355 "unitparse.tab.c" /* yacc.c:1646 */
13541355
break;
13551356

13561357
case 10:
1357-
#line 91 "unitparse.y" /* yacc.c:1646 */
1358+
#line 92 "unitparse.y" /* yacc.c:1646 */
13581359
{
13591360
unit_mult_internal(&(*(UnitShift*)(&yyvsp[-2])).unit, &(*(UnitShift*)(&yyvsp[0])).unit, &(*(UnitShift*)(&yyval)).unit);
13601361
(*(UnitShift*)(&yyval)).shift = 0.0;
13611362
}
1362-
#line 1363 "unitparse.tab.c" /* yacc.c:1646 */
1363+
#line 1364 "unitparse.tab.c" /* yacc.c:1646 */
13631364
break;
13641365

13651366
case 11:
1366-
#line 95 "unitparse.y" /* yacc.c:1646 */
1367+
#line 96 "unitparse.y" /* yacc.c:1646 */
13671368
{
13681369
unit_div_internal(&(*(UnitShift*)(&yyvsp[-2])).unit, &(*(UnitShift*)(&yyvsp[0])).unit, &(*(UnitShift*)(&yyval)).unit);
13691370
(*(UnitShift*)(&yyval)).shift = 0.0;
13701371
}
1371-
#line 1372 "unitparse.tab.c" /* yacc.c:1646 */
1372+
#line 1373 "unitparse.tab.c" /* yacc.c:1646 */
13721373
break;
13731374

13741375
case 12:
1375-
#line 99 "unitparse.y" /* yacc.c:1646 */
1376+
#line 100 "unitparse.y" /* yacc.c:1646 */
13761377
{
13771378
Unit nominator = { 1.0, {0} };
13781379
unit_div_internal(&nominator, &(*(UnitShift*)(&yyvsp[0])).unit, &(*(UnitShift*)(&yyval)).unit);
13791380
(*(UnitShift*)(&yyval)).shift = 0.0;
13801381
}
1381-
#line 1382 "unitparse.tab.c" /* yacc.c:1646 */
1382+
#line 1383 "unitparse.tab.c" /* yacc.c:1646 */
13821383
break;
13831384

13841385
case 13:
1385-
#line 107 "unitparse.y" /* yacc.c:1646 */
1386+
#line 108 "unitparse.y" /* yacc.c:1646 */
13861387
{
13871388
(*(UnitShift*)(&yyval)).unit.value = (*(double*)(&yyvsp[0]));
13881389
memset(&(*(UnitShift*)(&yyval)).unit.units, 0, N_UNITS);
13891390
(*(UnitShift*)(&yyval)).shift = 0.0;
13901391
}
1391-
#line 1392 "unitparse.tab.c" /* yacc.c:1646 */
1392+
#line 1393 "unitparse.tab.c" /* yacc.c:1646 */
13921393
break;
13931394

13941395
case 15:
1395-
#line 113 "unitparse.y" /* yacc.c:1646 */
1396+
#line 114 "unitparse.y" /* yacc.c:1646 */
13961397
{
13971398
(*(UnitShift*)(&yyval)) = (*(UnitShift*)(&yyvsp[-1]));
13981399
(*(UnitShift*)(&yyval)).shift = 0.0;
13991400
}
1400-
#line 1401 "unitparse.tab.c" /* yacc.c:1646 */
1401+
#line 1402 "unitparse.tab.c" /* yacc.c:1646 */
14011402
break;
14021403

14031404
case 17:
1404-
#line 120 "unitparse.y" /* yacc.c:1646 */
1405+
#line 121 "unitparse.y" /* yacc.c:1646 */
14051406
{
14061407
(*(double*)(&yyval)) = (*(double*)(&yyvsp[-2])) / (*(double*)(&yyvsp[0]));
14071408
}
1408-
#line 1409 "unitparse.tab.c" /* yacc.c:1646 */
1409+
#line 1410 "unitparse.tab.c" /* yacc.c:1646 */
14091410
break;
14101411

14111412
case 19:
1412-
#line 126 "unitparse.y" /* yacc.c:1646 */
1413+
#line 127 "unitparse.y" /* yacc.c:1646 */
14131414
{ (*(int*)(&yyval)) = (*(int*)(&yyvsp[-1])) * (*(int*)(&yyvsp[0])); }
1414-
#line 1415 "unitparse.tab.c" /* yacc.c:1646 */
1415+
#line 1416 "unitparse.tab.c" /* yacc.c:1646 */
14151416
break;
14161417

14171418
case 22:
1418-
#line 132 "unitparse.y" /* yacc.c:1646 */
1419+
#line 133 "unitparse.y" /* yacc.c:1646 */
14191420
{ (*(int*)(&yyval)) = 10 * (*(int*)(&yyvsp[-1])) + (*(int*)(&yyvsp[0])); }
1420-
#line 1421 "unitparse.tab.c" /* yacc.c:1646 */
1421+
#line 1422 "unitparse.tab.c" /* yacc.c:1646 */
14211422
break;
14221423

14231424

1424-
#line 1425 "unitparse.tab.c" /* yacc.c:1646 */
1425+
#line 1426 "unitparse.tab.c" /* yacc.c:1646 */
14251426
default: break;
14261427
}
14271428
/* User semantic actions sometimes alter yychar, and that requires
@@ -1649,7 +1650,7 @@ yyparse (void)
16491650
#endif
16501651
return yyresult;
16511652
}
1652-
#line 135 "unitparse.y" /* yacc.c:1906 */
1653+
#line 136 "unitparse.y" /* yacc.c:1906 */
16531654

16541655

16551656
/* parse a given string and return the result via the second argument */

unitparse.y

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ expr:
8585
}
8686
| expr expr %prec '*' {
8787
unit_mult_internal(&$1.unit, &$2.unit, &$$.unit);
88-
$$.unit.value += $2.shift; /* shift is evaluated exactly here */
88+
if ($2.shift != 0.0) /* avoid shift to not destroy -0 */
89+
$$.unit.value += $2.shift; /* shift is evaluated exactly here */
8990
$$.shift = 0.0;
9091
}
9192
| expr '*' expr {

0 commit comments

Comments
 (0)