Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e994c816
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e994c816
编写于
8月 27, 2009
作者:
X
xlu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6876282: BigDecimal's divide(BigDecimal bd, RoundingFormat r) produces incorrect result
Reviewed-by: darcy
上级
78b7659e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
4 deletion
+42
-4
src/share/classes/java/math/BigDecimal.java
src/share/classes/java/math/BigDecimal.java
+12
-3
test/java/math/BigDecimal/DivideTests.java
test/java/math/BigDecimal/DivideTests.java
+30
-1
未找到文件。
src/share/classes/java/math/BigDecimal.java
浏览文件 @
e994c816
...
...
@@ -315,6 +315,10 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
new
BigDecimal
(
BigInteger
.
ZERO
,
0
,
15
,
1
),
};
// Half of Long.MIN_VALUE & Long.MAX_VALUE.
private
static
final
long
HALF_LONG_MAX_VALUE
=
Long
.
MAX_VALUE
/
2
;
private
static
final
long
HALF_LONG_MIN_VALUE
=
Long
.
MIN_VALUE
/
2
;
// Constants
/**
* The value 0, with a scale of 0.
...
...
@@ -1455,10 +1459,15 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
}
else
if
(
roundingMode
==
ROUND_FLOOR
)
{
// Towards -infinity
increment
=
(
qsign
<
0
);
}
else
{
if
(
isLongDivision
||
ldivisor
!=
INFLATED
)
cmpFracHalf
=
longCompareMagnitude
(
2
*
r
,
ldivisor
);
else
if
(
isLongDivision
||
ldivisor
!=
INFLATED
)
{
if
(
r
<=
HALF_LONG_MIN_VALUE
||
r
>
HALF_LONG_MAX_VALUE
)
{
cmpFracHalf
=
1
;
// 2 * r can't fit into long
}
else
{
cmpFracHalf
=
longCompareMagnitude
(
2
*
r
,
ldivisor
);
}
}
else
{
cmpFracHalf
=
mr
.
compareHalf
(
mdivisor
);
}
if
(
cmpFracHalf
<
0
)
increment
=
false
;
// We're closer to higher digit
else
if
(
cmpFracHalf
>
0
)
// We're closer to lower digit
...
...
test/java/math/BigDecimal/DivideTests.java
浏览文件 @
e994c816
...
...
@@ -23,7 +23,7 @@
/*
* @test
* @bug 4851776 4907265 6177836
* @bug 4851776 4907265 6177836
6876282
* @summary Some tests for the divide methods.
* @author Joseph D. Darcy
* @compile -source 1.5 DivideTests.java
...
...
@@ -328,6 +328,35 @@ public class DivideTests {
}
}
// 6876282
BigDecimal
[][]
testCases2
=
{
// { dividend, divisor, expected quotient }
{
new
BigDecimal
(
3090
),
new
BigDecimal
(
7
),
new
BigDecimal
(
441
)
},
{
new
BigDecimal
(
"309000000000000000000000"
),
new
BigDecimal
(
"700000000000000000000"
),
new
BigDecimal
(
441
)
},
{
new
BigDecimal
(
"962.430000000000"
),
new
BigDecimal
(
"8346463.460000000000"
),
new
BigDecimal
(
"0.000115309916"
)
},
{
new
BigDecimal
(
"18446744073709551631"
),
new
BigDecimal
(
"4611686018427387909"
),
new
BigDecimal
(
4
)
},
{
new
BigDecimal
(
"18446744073709551630"
),
new
BigDecimal
(
"4611686018427387909"
),
new
BigDecimal
(
4
)
},
{
new
BigDecimal
(
"23058430092136939523"
),
new
BigDecimal
(
"4611686018427387905"
),
new
BigDecimal
(
5
)
},
{
new
BigDecimal
(
"-18446744073709551661"
),
new
BigDecimal
(
"-4611686018427387919"
),
new
BigDecimal
(
4
)
},
{
new
BigDecimal
(
"-18446744073709551660"
),
new
BigDecimal
(
"-4611686018427387919"
),
new
BigDecimal
(
4
)
},
};
for
(
BigDecimal
test
[]
:
testCases2
)
{
BigDecimal
quo
=
test
[
0
].
divide
(
test
[
1
],
RoundingMode
.
HALF_UP
);
if
(!
quo
.
equals
(
test
[
2
]))
{
failures
++;
System
.
err
.
println
(
"Unexpected quotient from "
+
test
[
0
]
+
" / "
+
test
[
1
]
+
" rounding mode HALF_UP"
+
"; expected "
+
test
[
2
]
+
" got "
+
quo
);
}
}
return
failures
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录