Bug 91481 - Decimal::toString should not round integer value.
Summary: Decimal::toString should not round integer value.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: yosin
URL:
Keywords:
Depends on: 91572 91579
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-17 03:00 PDT by yosin
Modified: 2012-07-18 01:09 PDT (History)
1 user (show)

See Also:


Attachments
Patch 1 (3.67 KB, patch)
2012-07-17 03:09 PDT, yosin
no flags Details | Formatted Diff | Diff
Patch 2 (4.46 KB, patch)
2012-07-17 19:22 PDT, yosin
no flags Details | Formatted Diff | Diff
Patch 3 (4.77 KB, patch)
2012-07-18 00:23 PDT, yosin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description yosin 2012-07-17 03:00:32 PDT
Following test case in LayoutTests/fast/forms/datetime/input-valueasnumber-datetime.html is failed:
  shouldBe('setValueAsNumberAndGetValue(275760, 8, 12, 0, 0, 0, 1)', '"275760-09-12T00:00:00.001Z"');

The root cause is Decimal::toString. It  converts an integer 8639999913600001 (= Date.UTC(275760, 8, 12, 0, 0, 0 1)) to a string "8639999913600000", the last digit "1" is converted to digit "0".
Comment 1 yosin 2012-07-17 03:09:12 PDT
Created attachment 152724 [details]
Patch 1
Comment 2 yosin 2012-07-17 03:11:40 PDT
Comment on attachment 152724 [details]
Patch 1

Could you review this patch?
Thanks in advance.

P.S.
Changes for Decimal.cpp is only adding "if (originalExponent < 0)" and indentation. git diff -w Decimal.cpp shows two line changes.
Comment 3 Kent Tamura 2012-07-17 03:40:00 PDT
Comment on attachment 152724 [details]
Patch 1

View in context: https://bugs.webkit.org/attachment.cgi?id=152724&action=review

> Source/WebCore/ChangeLog:14
> +        (WebCore::Decimal::toString): When the value is an integer, we don't
> +        round coefficient to DBL_DIG(15) digits.

Why do we need the rounding for non-integer cases?

> Source/WebKit/chromium/tests/DecimalTest.cpp:1045
> +    // 8639999913600001=Date.UTC(275760, 8, 12, 0, 0, 0 1)

Understing it helps nothing.  Please remove the comment.

> Source/WebKit/chromium/tests/DecimalTest.cpp:1046
> +    EXPECT_STREQ(("8639999913600001"), encode(8639999913600001, 0, Positive).toString().ascii().data());

We need more test cases.  For example, MaxCoefficient with various exponents.
Comment 4 yosin 2012-07-17 19:22:20 PDT
Created attachment 152904 [details]
Patch 2
Comment 5 yosin 2012-07-18 00:23:12 PDT
Created attachment 152949 [details]
Patch 3
Comment 6 yosin 2012-07-18 00:29:52 PDT
(In reply to comment #3)
> (From update of attachment 152724 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=152724&action=review
> 
> > Source/WebCore/ChangeLog:14
> > +        (WebCore::Decimal::toString): When the value is an integer, we don't
> > +        round coefficient to DBL_DIG(15) digits.
> 
> Why do we need the rounding for non-integer cases?

The reason is we would like to get "1" for 1/3 * 3 or 1/256 * 256. Using DBL_DIG is chosen by converting Decimal to double, e.g. HTMLInputElement.valueAsNumber method.
Comment 7 yosin 2012-07-18 00:31:11 PDT
Comment on attachment 152949 [details]
Patch 3

Could you review this patch?
Thanks in advance.

= Changes since the last review =
* Added more tests as suggested.
* Use newly introduced macro EXPECT_DECIMAL_STREQ.
Comment 8 Kent Tamura 2012-07-18 00:45:25 PDT
Comment on attachment 152949 [details]
Patch 3

ok
Comment 9 yosin 2012-07-18 01:09:53 PDT
Comment on attachment 152949 [details]
Patch 3

Clearing flags on attachment: 152949

Committed r122928: <http://trac.webkit.org/changeset/122928>
Comment 10 yosin 2012-07-18 01:09:59 PDT
All reviewed patches have been landed.  Closing bug.