You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Yang Paulex <pa...@gmail.com> on 2007/08/15 05:56:14 UTC

[classlib][math]Non-bug difference? (was Re: [jira] Created: (HARMONY-4623) BigDecimal.stripTrailingZero fails for 0.0000)

Hi, all,

I'm looking at this issue, the spec on BigDecimal.stripTrialingZeros()
mentioned:

"Returns a BigDecimal which is numerically equal to this one but with any
trailing zeros removed from the representation. For example, stripping the
trailing zeros from the BigDecimal value 600.0, which has [BigInteger, scale]
components equals to [6000, 1], yields 6E2 with [BigInteger, scale]
components equals to [6, -2]"

While seems new BigDecimal("0.0000").stripTrialingZeros() just return this
without any changes, IMHO this is contradict with spec. Currently Harmony
has same behavior, should we follow RI or spec here?

A quick and naive fix would be:

--- main/java/java/math/BigDecimal.java (修订版 566012)
+++ main/java/java/math/BigDecimal.java (工作拷贝)
@@ -1314,7 +1314,7 @@
         long newScale = scale;

         if (isZero()) {
-            return this;
+            return new BigDecimal("0");
         }

2007/8/14, Imran Ghory (JIRA) <ji...@apache.org>:
>
> BigDecimal.stripTrailingZero fails for 0.0000
> ---------------------------------------------
>
>                  Key: HARMONY-4623
>                  URL: https://issues.apache.org/jira/browse/HARMONY-4623
>              Project: Harmony
>           Issue Type: Bug
>           Components: Classlib
>             Reporter: Imran Ghory
>             Priority: Minor
>
>
> BigDecimal.stripTrailingZero fails for "0.0000" (leaves it unstriped).
> This behaviour occurs in the RI as well, however from the specification it
> seems this behaviour is incorrect. Will attach test case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>


-- 
Paulex Yang
China Software Development laboratory
IBM

Re: [classlib][math]Non-bug difference? (was Re: [jira] Created: (HARMONY-4623) BigDecimal.stripTrailingZero fails for 0.0000)

Posted by Oliver Deakin <ol...@googlemail.com>.
Hi Paulex,

This looks to me to be a bug in the RI. I think the spec is clear on what
the returned BigDecimal representation should be. If we follow the
guidelines at [1], then I would say that we should follow the spec in this
case until we find a reason to go with the RI version (like an app. that
relies on this result, although I cannot imagine that happening).

Do you agree?

Regards,
Oliver

[1] http://harmony.apache.org/subcomponents/classlibrary/compat.html

On 8/15/07, Yang Paulex <pa...@gmail.com> wrote:
>
> Hi, all,
>
> I'm looking at this issue, the spec on BigDecimal.stripTrialingZeros()
> mentioned:
>
> "Returns a BigDecimal which is numerically equal to this one but with any
> trailing zeros removed from the representation. For example, stripping the
> trailing zeros from the BigDecimal value 600.0, which has [BigInteger,
> scale]
> components equals to [6000, 1], yields 6E2 with [BigInteger, scale]
> components equals to [6, -2]"
>
> While seems new BigDecimal("0.0000").stripTrialingZeros() just return this
> without any changes, IMHO this is contradict with spec. Currently Harmony
> has same behavior, should we follow RI or spec here?
>
> A quick and naive fix would be:
>
> --- main/java/java/math/BigDecimal.java (修订版 566012)
> +++ main/java/java/math/BigDecimal.java (工作拷贝)
> @@ -1314,7 +1314,7 @@
>         long newScale = scale;
>
>         if (isZero()) {
> -            return this;
> +            return new BigDecimal("0");
>         }
>
> 2007/8/14, Imran Ghory (JIRA) <ji...@apache.org>:
> >
> > BigDecimal.stripTrailingZero fails for 0.0000
> > ---------------------------------------------
> >
> >                  Key: HARMONY-4623
> >                  URL: https://issues.apache.org/jira/browse/HARMONY-4623
> >              Project: Harmony
> >           Issue Type: Bug
> >           Components: Classlib
> >             Reporter: Imran Ghory
> >             Priority: Minor
> >
> >
> > BigDecimal.stripTrailingZero fails for "0.0000" (leaves it unstriped).
> > This behaviour occurs in the RI as well, however from the specification
> it
> > seems this behaviour is incorrect. Will attach test case.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>
>
> --
> Paulex Yang
> China Software Development laboratory
> IBM
>

Re: [classlib][math]Non-bug difference? (was Re: [jira] Created: (HARMONY-4623) BigDecimal.stripTrailingZero fails for 0.0000)

Posted by Yang Paulex <pa...@gmail.com>.
2007/8/15, Mikhail Loenko <ml...@gmail.com>:
>
> Hi Paulex
>
> for some reason my mails to the dev list return. See my response below.
> Feel free to CC dev list if responding
>
> Thanks,
> Mikhail
>
> ---------- Forwarded message ----------
> From: Mikhail Loenko <ml...@gmail.com>
> Date: 15.08.2007 15:42
> Subject: Re: [classlib][math]Non-bug difference? (was Re: [jira]
> Created: (HARMONY-4623) BigDecimal.stripTrailingZero fails for 0.0000)
> To: dev@harmony.apache.org
>
>
> Can you imagine a real app that would break if we change Harmony to
> follow the spec?


No, I cannot...I'm going to fix it following spec if no one objects.

Thanks,
> Mikhail
>
> 2007/8/15, Yang Paulex <pa...@gmail.com>:
> > Hi, all,
> >
> > I'm looking at this issue, the spec on BigDecimal.stripTrialingZeros()
> > mentioned:
> >
> > "Returns a BigDecimal which is numerically equal to this one but with
> any
> > trailing zeros removed from the representation. For example, stripping
> the
> > trailing zeros from the BigDecimal value 600.0, which has [BigInteger,
> scale]
> > components equals to [6000, 1], yields 6E2 with [BigInteger, scale]
> > components equals to [6, -2]"
> >
> > While seems new BigDecimal("0.0000").stripTrialingZeros() just return
> this
> > without any changes, IMHO this is contradict with spec. Currently
> Harmony
> > has same behavior, should we follow RI or spec here?
> >
> > A quick and naive fix would be:
> >
> > --- main/java/java/math/BigDecimal.java (修订版 566012)
> > +++ main/java/java/math/BigDecimal.java (工作拷贝)
> > @@ -1314,7 +1314,7 @@
> >         long newScale = scale;
> >
> >         if (isZero()) {
> > -            return this;
> > +            return new BigDecimal("0");
> >         }
> >
> > 2007/8/14, Imran Ghory (JIRA) <ji...@apache.org>:
> > >
> > > BigDecimal.stripTrailingZero fails for 0.0000
> > > ---------------------------------------------
> > >
> > >                  Key: HARMONY-4623
> > >                  URL:
> https://issues.apache.org/jira/browse/HARMONY-4623
> > >              Project: Harmony
> > >           Issue Type: Bug
> > >           Components: Classlib
> > >             Reporter: Imran Ghory
> > >             Priority: Minor
> > >
> > >
> > > BigDecimal.stripTrailingZero fails for "0.0000" (leaves it unstriped).
> > > This behaviour occurs in the RI as well, however from the
> specification it
> > > seems this behaviour is incorrect. Will attach test case.
> > >
> > > --
> > > This message is automatically generated by JIRA.
> > > -
> > > You can reply to this email to add a comment to the issue online.
> > >
> > >
> >
> >
> > --
> > Paulex Yang
> > China Software Development laboratory
> > IBM
> >
>



-- 
Paulex Yang
China Software Development laboratory
IBM