<< Back to previous view

[CLJ-354] <= and >= comparisons against NaN return true Created: 22/May/10  Updated: 19/Mar/11  Resolved: 01/Oct/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: Backlog

Type: Defect
Reporter: Anonymous Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None


 Description   

I would expect the attached clojure program to have the same output as the attached java program. However, their output differs. The following is a unidiff from the clojure output to the java output, i.e., each line beginning with a minus sign is what I would consider wrong output, and the corresponding line beginning with a plus sign is the correct output.

@@ -14,3 +14,3 @@

  • <= 0 NaN true
  • <= NaN 1 true
  • <= NaN NaN true
    + <= 0 NaN false
    + <= NaN 1 false
    + <= NaN NaN false
    @@ -22,3 +22,3 @@
  • >= 0 NaN true
  • >= NaN 1 true
  • >= NaN NaN true
    + >= 0 NaN false
    + >= NaN 1 false
    + >= NaN NaN false

Here Java follows IEEE 754; see also <http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#153654>.

I suspect the bug is because clojure.lang.Numbers.lte(x,y) is implemented by negating the result of lt(y,x), and similarly for gte: <http://github.com/richhickey/clojure/blob/65ae4928119a50e892bc33e8cbb47a82ebef98ee/src/jvm/clojure/lang/Numbers.java#L193>.

This is with Clojure 1.2.0-master-SNAPSHOT (git hash 65ae4928119a50e892bc33e8cbb47a82ebef98ee).

I mentioned this on the Google group, but no-one commented anything: <http://groups.google.com/group/clojure/browse_thread/thread/623d7f50fafaa816>.



 Comments   
Comment by Assembla Importer [ 01/Oct/10 4:14 PM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/354
Attachments:
nan-comparison.clj - https://www.assembla.com/spaces/clojure/documents/bSK-9AzyGr35jbeJe5cbLr/download/bSK-9AzyGr35jbeJe5cbLr
nan.java - https://www.assembla.com/spaces/clojure/documents/bSLbjAzyGr35jbeJe5cbLr/download/bSLbjAzyGr35jbeJe5cbLr
c-nan.txt - https://www.assembla.com/spaces/clojure/documents/bSLdpEzyGr35jbeJe5cbLr/download/bSLdpEzyGr35jbeJe5cbLr
j-nan.txt - https://www.assembla.com/spaces/clojure/documents/bSLft0zyGr35jbeJe5cbLr/download/bSLft0zyGr35jbeJe5cbLr

Comment by Assembla Importer [ 01/Oct/10 4:14 PM ]

stu said: This appears to be fixed in 1.3 master.

Comment by Jouni K. Seppänen [ 19/Mar/11 2:52 PM ]

Not fixed on current git master: the test program still prints e.g. <= 0 NaN true. Interestingly, (<= (float 0.0) Float/NaN) returns false, while (let [op <=] (op (float 0.0) Float/NaN)) returns true.

Comment by Alexander Taggart [ 19/Mar/11 6:44 PM ]

See CLJ-738.

Generated at Tue Oct 21 10:20:24 CDT 2014 using JIRA 4.4#649-r158309.