@ 261102.1

261020.2 · afa23a53cde43cbd7d6e5d91ae759e342d518de6

Keep the sign of zero when negating a number literal (#3662)

Since jq 1.8.0, negating a number literal computed 0 - x, so -0 and 0 | -. printed 0 while (0+0) | -. printed -0.

Flip the sign bit with decNumberCopyNegate() instead, so -0 prints -0 again as it did in jq 1.7, and -(-0) is still 0.

reading declarations

Changes to src/jv.c. All files

src/jv.c

@@ -758,7 +758,7 @@ jv jv_number_negate(jv n) {   if (JVP_HAS_FLAGS(n, JVP_FLAGS_NUMBER_LITERAL)) {     jvp_literal_number* m = jvp_literal_number_alloc(jvp_dec_number_ptr(n)->digits); -    decNumberMinus(&m->num_decimal, jvp_dec_number_ptr(n), DEC_CONTEXT());+    decNumberCopyNegate(&m->num_decimal, jvp_dec_number_ptr(n));     jv r = {JVP_FLAGS_NUMBER_LITERAL, 0, 0, 0, {&m->refcnt}};     return r;   }