Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-7594

Float/DoublePoint should not recommend using Math.nextUp/nextDown for exclusive ranges

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.0, 6.4
    • Component/s: None
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      Float/Double points are supposed to be consistent with Double/Float.compare, so +0 is supposed to compare greater than -0. However Math.nextUp/nextDown is not consistent with Double/Float.compare and returns MIN_VALUE for nextUp(-0).

        Activity

        Hide
        jpountz Adrien Grand added a comment -

        Here is a patch that adds an alternative nextUp/nextDown impl that treats -0 and +0 as different values.

        Show
        jpountz Adrien Grand added a comment - Here is a patch that adds an alternative nextUp/nextDown impl that treats -0 and +0 as different values.
        Hide
        dweiss Dawid Weiss added a comment -

        Ah, that is trappy... In a way it makes sense as -0.0f is 8000_0000 and min value is 0000_0001, so if you disregard the sign bit there's some logic there.

        Patch looks good. I don't know if the compiler will be smart enough to avoid recomputing the static Float.floatToIntBits(-0f). An alternative would be to:

        if (Float.compare(f, -0.0) == 0)
        

        or simply compare the int representation (Float.toIntBits(f) == 0x8000_0000). Either way, looks good to me.

        Show
        dweiss Dawid Weiss added a comment - Ah, that is trappy... In a way it makes sense as -0.0f is 8000_0000 and min value is 0000_0001, so if you disregard the sign bit there's some logic there. Patch looks good. I don't know if the compiler will be smart enough to avoid recomputing the static Float.floatToIntBits(-0f) . An alternative would be to: if ( Float .compare(f, -0.0) == 0) or simply compare the int representation (Float.toIntBits(f) == 0x8000_0000). Either way, looks good to me.
        Hide
        jpountz Adrien Grand added a comment -

        Thanks for having a look Dawid. I'll apply your suggestion when pushing.

        Show
        jpountz Adrien Grand added a comment - Thanks for having a look Dawid. I'll apply your suggestion when pushing.
        Hide
        dweiss Dawid Weiss added a comment -

        I checked and javac doesn't recognize it as a static expression, for example:

              10: ldc           #31                 // float -0.0f
              12: invokestatic  #27                 // Method java/lang/Float.floatToIntBits:(F)I
        

        very likely it'd be optimized away later in hotspot, but any of the alternatives I mentioned are just as good.

        Show
        dweiss Dawid Weiss added a comment - I checked and javac doesn't recognize it as a static expression, for example: 10: ldc #31 // float -0.0f 12: invokestatic #27 // Method java/lang/ Float .floatToIntBits:(F)I very likely it'd be optimized away later in hotspot, but any of the alternatives I mentioned are just as good.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 10f19641942716ed9de804d43dd3c21898a1e890 in lucene-solr's branch refs/heads/branch_6x from Adrien Grand
        [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=10f1964 ]

        LUCENE-7594: Fixed point range queries on floating-point types to recommend using helpers for exclusive bounds that are consistent with Double.compare.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 10f19641942716ed9de804d43dd3c21898a1e890 in lucene-solr's branch refs/heads/branch_6x from Adrien Grand [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=10f1964 ] LUCENE-7594 : Fixed point range queries on floating-point types to recommend using helpers for exclusive bounds that are consistent with Double.compare.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 18d53a43f7b4536572ef98a94ec1d9b529084d1b in lucene-solr's branch refs/heads/master from Adrien Grand
        [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=18d53a4 ]

        LUCENE-7594: Fixed point range queries on floating-point types to recommend using helpers for exclusive bounds that are consistent with Double.compare.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 18d53a43f7b4536572ef98a94ec1d9b529084d1b in lucene-solr's branch refs/heads/master from Adrien Grand [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=18d53a4 ] LUCENE-7594 : Fixed point range queries on floating-point types to recommend using helpers for exclusive bounds that are consistent with Double.compare.

          People

          • Assignee:
            Unassigned
            Reporter:
            jpountz Adrien Grand
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development