Clojure

<= is incorrect when args include Double/NaN

Details

  • Type: Defect Defect
  • Status: Reopened Reopened
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
  • Environment:
    Mac OS X, Java 6
  • Patch:
    Code and Test
  • Approval:
    Screened

Description

user=> (<= Double/NaN 1)
false  
user=> (<= (double Double/NaN) 1)
true    ;; should match Double object result

Cause: The problem was that the logic for lte/gte depended on the fact that lte is equivalent to !gt.
However, in Java, this assumption is invalid - any comparison involving NaN always yields false.

Solution: The fix was to adding lte and gte methods to Numbers.Ops directly, rather than implementing everything in terms of lt. This was the only fix I could see that didn't incur the cost of runtime checks for NaN.

Patch: clj-738-v2.diff

Screened by: Alex Miller

  1. 738.diff
    26/Aug/11 11:33 AM
    4 kB
    Luke VanderHart
  2. 738-tests.diff
    26/Aug/11 11:33 AM
    3 kB
    Luke VanderHart
  3. clj-738-v2.diff
    18/Apr/14 11:41 AM
    6 kB
    Andy Fingerhut

Activity

People

Vote (1)
Watch (6)

Dates

  • Created:
    Updated: