[ 
https://issues.apache.org/jira/browse/LUCENE-3582?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13153189#comment-13153189
 ] 

Dawid Weiss commented on LUCENE-3582:
-------------------------------------

bq. So you agree if we exchange with flotToIntBits the bug is fixed.

Yes, as far as I can see the implementation of floatToIntBits is exactly 
floatToRawIntBits + normalization of NaN. I doubt there'll be intrinsics for 
that -- the code is short and simple enough that it will probably inline and 
jit into a few assembly instructions anyway.

I don't quite understand the other part of your question... the code in my 
patch is virtually the same as floatToIntBits:


        int result = floatToRawIntBits(value);
        // Check for NaN based on values of bit fields, maximum
        // exponent and nonzero significand.
        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
              FloatConsts.EXP_BIT_MASK) &&
             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
            result = 0x7fc00000;
        return result;

The only difference is that this doesn't normalize "significant" NaNs 
(failing), but I don't know if they're even used in jvm code anywhere.
                
> NumericUtils.floatToSortableInt does not sort certain NaN ranges correctly.
> ---------------------------------------------------------------------------
>
>                 Key: LUCENE-3582
>                 URL: https://issues.apache.org/jira/browse/LUCENE-3582
>             Project: Lucene - Java
>          Issue Type: Bug
>            Reporter: Dawid Weiss
>            Assignee: Uwe Schindler
>            Priority: Trivial
>             Fix For: 4.0
>
>         Attachments: LUCENE-3582.patch
>
>
> The current implementation of floatToSortableInt does not account for 
> different NaN ranges which may result in NaNs sorted before -Infinity and 
> after +Infinity. The default Java ordering is: all NaNs after Infinity.
> A possible fix is to make all NaNs canonic "quiet NaN" as in:
> {code}
> // Canonicalize NaN ranges. I assume this check will be faster here than 
> // (v == v) == false on the FPU? We don't distinguish between different
> // flavors of NaNs here (see http://en.wikipedia.org/wiki/NaN). I guess
> // in Java this doesn't matter much anyway.
> if ((v & 0x7fffffff) > 0x7f800000) {
>   // Apply the logic below to a canonical "quiet NaN"
>   return 0x7fc00000 ^ 0x80000000;
> }
> {code}
> I don't commit because I don't know how much of the existing stuff relies on 
> this (nobody should be keeping different NaNs  in their indexes, but who 
> knows...).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to