jqlang / jq

Command-line JSON processor
https://jqlang.github.io/jq/
Other
29.59k stars 1.54k forks source link

Multiplying -1 with 0 must result 0, not -0 #3102

Closed mkipcak-hrlabs closed 2 months ago

mkipcak-hrlabs commented 2 months ago

Describe the bug Multiplying -1 with 0 must result 0, not -0

To Reproduce Execute this command below jq -n '0 * -1'

Expected behavior Mathematically speaking, the result of this mathematical operation (zero times minus 1) should be zero(0) and not minus zero (-0).

Environment (please complete the following information): any

Additional context

itchyny commented 2 months ago

Zero is singed in IEEE 754 and this is working as intended.

wader commented 2 months ago

@mkipcak-hrlabs could elaborate on what problem this causes? node seem to behave the same but not python. I also noticed this behaviour 🤔

$ jq -n '-0 | abs, fabs'
-0
0