Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e63a078

Browse files
committed
Preserve sign of -0.0 when result is run through marshal.
1 parent 71dcc3e commit e63a078

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Python/compile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
545545
static int
546546
fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
547547
{
548-
PyObject *newconst, *v;
548+
PyObject *newconst=NULL, *v;
549549
int len_consts, opcode;
550550

551551
/* Pre-conditions */
@@ -557,7 +557,9 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
557557
opcode = codestr[3];
558558
switch (opcode) {
559559
case UNARY_NEGATIVE:
560-
newconst = PyNumber_Negative(v);
560+
/* Preserve the sign of -0.0 */
561+
if (PyObject_IsTrue(v) == 1)
562+
newconst = PyNumber_Negative(v);
561563
break;
562564
case UNARY_CONVERT:
563565
newconst = PyObject_Repr(v);

0 commit comments

Comments
 (0)