Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] optimize BigDecimal.divide #849

Merged
merged 1 commit into from
Aug 7, 2024
Merged

[Misc] optimize BigDecimal.divide #849

merged 1 commit into from
Aug 7, 2024

Conversation

weixlu
Copy link
Collaborator

@weixlu weixlu commented Jul 31, 2024

Summary: Use binary search in zero stripping of BigDecimal.divide

Testing: jtreg

Reviewers:

Issue: #848

@weixlu weixlu requested a review from sandlerwang July 31, 2024 07:50
weixlu added a commit that referenced this pull request Jul 31, 2024
Summary: Use binary search in zero stripping of BigDecimal.divide

Testing: jtreg

Reviewers:

Issue: #848

CR: #849
Class<BigDecimal> clazz = BigDecimal.class;
Field optField = clazz.getDeclaredField("opt");
optField.setAccessible(true);
SecureRandom random = new SecureRandom();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 这里需要加一些边界条件检查,不能全依赖随机测试

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要加一些边界条件检查,不能全依赖随机测试

好的, 增加了下列特殊情况
0.00000000000000D,
123456789.123456789, -123456789.123456789,
1e10, 1e-010, -1e10, -1e-010,
Double.MAX_VALUE, Double.MIN_VALUE,
-Double.MAX_VALUE, -Double.MIN_VALUE

@@ -368,6 +368,18 @@ protected StringBuilderHelper initialValue() {
*/
private static final BigDecimal ONE_HALF = valueOf(5L, 1);

private static boolean opt;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否应该在opt声明的时候加上默认值,下面的try-catch没有final语句,如果有一些特殊异常情况可能导致opt没赋上值

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完成,默认设置false

weixlu added a commit that referenced this pull request Aug 2, 2024
Summary: Use binary search in zero stripping of BigDecimal.divide

Testing: jtreg

Reviewers: zhuoren.wz, JoshuaZhuwj

Issue: #848

CR: #849
@weixlu weixlu force-pushed the decimal branch 4 times, most recently from 7a96e2c to 5f9464c Compare August 5, 2024 06:30
@weixlu weixlu changed the title [Runtime] optimize BigDecimal.divide [Misc] optimize BigDecimal.divide Aug 5, 2024
Summary: Use binary search in zero stripping of BigDecimal.divide

Testing: jtreg and ci

Reviewers: zhuoren.wz, JoshuaZhuwj

Issue: #848
@weixlu weixlu requested a review from JoshuaZhuwj August 6, 2024 06:29
Copy link
Collaborator

@JoshuaZhuwj JoshuaZhuwj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@weixlu weixlu merged commit 2f3215f into master Aug 7, 2024
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants