Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4018

Make the Groovy truth value of NaN be false

    XMLWordPrintableJSON

Details

    Description

      Similar to null and empty-string, have Groovy evaluate NaN as false rather than true.

      def result = a?.b?.calcX(...)
      if (result) { 
        // now I have a valid non-null number
      }
      

      This is how JavaScript treats NaN and like other Groovy design choices, it just makes sense.

      Discussed in this thread
      http://old.nabble.com/Shouldn't-the-Groovy-truth-value-of-NaN-be-false--tt27348256.html

      That is, if NaN was false the following should work:

      assert !(Double.NaN)

      assert !((Double.NaN as Boolean) == true)

      assert ((Double.NaN as Boolean) == false)

      Attachments

        Issue Links

          Activity

            People

              jwagenleitner John Wagenleitner
              stekell Steve Tekell
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: