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: None
  • Component/s: None
  • Labels:
  • Environment:
    Mac OS X, Java 6
  • Patch:
    Code and Test
  • Approval:
    Vetted

Description

user=> (<= (long Double/NaN) 1)
true     
user=> (<= Double/NaN 1)
false  ;; should match primitive version

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: 738.diff, 738-tests.diff

Screened by:

  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

Activity

People

Vote (1)
Watch (6)

Dates

  • Created:
    Updated: