MiSawa / xq

Pure rust implementation of jq
MIT License
333 stars 18 forks source link

Fix isfinite, isinfinite on nan #92

Closed itchyny closed 2 years ago

itchyny commented 2 years ago

I noticed that xq -n "nan | isfinite" prints false but this is different from jq.

❯ jq -nc '0, nan, infinite, -infinite | [isfinite, isinfinite]'
[true,false]
[true,false]
[false,true]
[false,true]

❯ xq -nc '0, nan, infinite, -infinite | [isfinite, isinfinite]'
[true,false]
[false,true] # oops!
[false,true]
[false,true]

❯ xq --version                                                 
xq 0.2.10-cb245914e46e2808bdaea20e415addeda7b36bad
MiSawa commented 2 years ago

Thank you for the PR! Hmmmm, I was aware of this difference when I implemented it, and followed what isfinite of C++ does. Though now I think returning true for isinfinite is also weird.... I'll merge this for now to match the behavior of jq, but might change in some future to make both isfinite and isinfinite return false for NaN.