RFR 8015978: Incorrect transformation of XPath expression "string(-0)"

huizhe wang huizhe.wang at oracle.com
Fri Jun 7 06:03:41 UTC 2013


Hi Aleksej,

According to XPath spec, both positive and negative zero are converted 
to the string 0, so it seems doesn't matter. But if you want to detect 
the negative zero, you may do the following:
     if (d == 0.0 && 1/d < 0.0) {
          d=0.0
     }

Recognizing that (-0.0 == 0.0), and (1/(-0.0) == -Infinity).

-Joe

On 6/6/2013 10:10 AM, Aleksej Efimov wrote:
> Hi,
>
> The expression "string(-0.0)" incorrectly transformed to -0, but it 
> should be 0 according to W3C specification: 
> http://www.w3.org/TR/xpath/#function-string
>
> The webrev with fix and the test case:
> http://cr.openjdk.java.net/~dmeetry/8015978/webrev.1/ 
> <http://cr.openjdk.java.net/%7Edmeetry/8015978/webrev.1/>
>
> There is another way of disabling the -0 result. In current webrev the 
> minus zero is processed with such code:
>
> +
> +        //Check for -0.0 and convert it to 0.0
> +        if (new Double(d).equals(new Double(-0.0))
> +        d=0.0;
>
> We can make the replace of -0 -> 0 faster (I think but didn't tested 
> it) with the following code, but it looks strange and will work both 
> for 0 and -0:
>
> +        //Check for -0.0 and convert it to 0.0
> +        if (d == 0.0)
> +        d=0.0;
>
> -Aleksej




More information about the core-libs-dev mailing list