Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
364bf2a3
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看板
提交
364bf2a3
编写于
5月 24, 2009
作者:
X
xlu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6622432: RFE: Performance improvements to java.math.BigDecimal
Reviewed-by: darcy
上级
ae34f917
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
1471 addition
and
1103 deletion
+1471
-1103
src/share/classes/java/math/BigDecimal.java
src/share/classes/java/math/BigDecimal.java
+903
-609
src/share/classes/java/math/BigInteger.java
src/share/classes/java/math/BigInteger.java
+280
-314
src/share/classes/java/math/BitSieve.java
src/share/classes/java/math/BitSieve.java
+2
-4
src/share/classes/java/math/MathContext.java
src/share/classes/java/math/MathContext.java
+0
-27
src/share/classes/java/math/MutableBigInteger.java
src/share/classes/java/math/MutableBigInteger.java
+252
-146
src/share/classes/java/math/SignedMutableBigInteger.java
src/share/classes/java/math/SignedMutableBigInteger.java
+1
-3
test/java/math/BigDecimal/AddTests.java
test/java/math/BigDecimal/AddTests.java
+25
-0
test/java/math/BigDecimal/DivideTests.java
test/java/math/BigDecimal/DivideTests.java
+8
-0
未找到文件。
src/share/classes/java/math/BigDecimal.java
浏览文件 @
364bf2a3
此差异已折叠。
点击以展开。
src/share/classes/java/math/BigInteger.java
浏览文件 @
364bf2a3
此差异已折叠。
点击以展开。
src/share/classes/java/math/BitSieve.java
浏览文件 @
364bf2a3
...
@@ -110,13 +110,11 @@ class BitSieve {
...
@@ -110,13 +110,11 @@ class BitSieve {
int
convertedStep
=
(
step
*
2
)
+
1
;
int
convertedStep
=
(
step
*
2
)
+
1
;
// Construct the large sieve at an even offset specified by base
// Construct the large sieve at an even offset specified by base
MutableBigInteger
r
=
new
MutableBigInteger
(
);
MutableBigInteger
b
=
new
MutableBigInteger
(
base
);
MutableBigInteger
q
=
new
MutableBigInteger
();
MutableBigInteger
q
=
new
MutableBigInteger
();
do
{
do
{
// Calculate base mod convertedStep
// Calculate base mod convertedStep
r
.
copyValue
(
base
.
mag
);
start
=
b
.
divideOneWord
(
convertedStep
,
q
);
r
.
divideOneWord
(
convertedStep
,
q
);
start
=
r
.
value
[
r
.
offset
];
// Take each multiple of step out of sieve
// Take each multiple of step out of sieve
start
=
convertedStep
-
start
;
start
=
convertedStep
-
start
;
...
...
src/share/classes/java/math/MathContext.java
浏览文件 @
364bf2a3
...
@@ -126,19 +126,6 @@ public final class MathContext implements Serializable {
...
@@ -126,19 +126,6 @@ public final class MathContext implements Serializable {
*/
*/
final
RoundingMode
roundingMode
;
final
RoundingMode
roundingMode
;
/**
* Lookaside for the rounding points (the numbers which determine
* whether the coefficient of a number will require rounding).
* These will be present if {@code precision > 0} and
* {@code precision <= MAX_LOOKASIDE}. In this case they will share the
* {@code BigInteger int[]} array. Note that the transients
* cannot be {@code final} because they are reconstructed on
* deserialization.
*/
transient
BigInteger
roundingMax
=
null
;
transient
BigInteger
roundingMin
=
null
;
private
static
final
int
MAX_LOOKASIDE
=
1000
;
/* ----- Constructors ----- */
/* ----- Constructors ----- */
/**
/**
...
@@ -173,11 +160,6 @@ public final class MathContext implements Serializable {
...
@@ -173,11 +160,6 @@ public final class MathContext implements Serializable {
throw
new
NullPointerException
(
"null RoundingMode"
);
throw
new
NullPointerException
(
"null RoundingMode"
);
precision
=
setPrecision
;
precision
=
setPrecision
;
if
(
precision
>
0
&&
precision
<=
MAX_LOOKASIDE
)
{
roundingMax
=
BigInteger
.
TEN
.
pow
(
precision
);
roundingMin
=
roundingMax
.
negate
();
}
roundingMode
=
setRoundingMode
;
roundingMode
=
setRoundingMode
;
return
;
return
;
}
}
...
@@ -221,10 +203,6 @@ public final class MathContext implements Serializable {
...
@@ -221,10 +203,6 @@ public final class MathContext implements Serializable {
throw
new
IllegalArgumentException
(
"Digits < 0"
);
throw
new
IllegalArgumentException
(
"Digits < 0"
);
// the other parameters cannot be invalid if we got here
// the other parameters cannot be invalid if we got here
precision
=
setPrecision
;
precision
=
setPrecision
;
if
(
precision
>
0
&&
precision
<=
MAX_LOOKASIDE
)
{
roundingMax
=
BigInteger
.
TEN
.
pow
(
precision
);
roundingMin
=
roundingMax
.
negate
();
}
}
}
/**
/**
...
@@ -343,11 +321,6 @@ public final class MathContext implements Serializable {
...
@@ -343,11 +321,6 @@ public final class MathContext implements Serializable {
String
message
=
"MathContext: null roundingMode in stream"
;
String
message
=
"MathContext: null roundingMode in stream"
;
throw
new
java
.
io
.
StreamCorruptedException
(
message
);
throw
new
java
.
io
.
StreamCorruptedException
(
message
);
}
}
// Set the lookaside, if applicable
if
(
precision
<=
MAX_LOOKASIDE
)
{
roundingMax
=
BigInteger
.
TEN
.
pow
(
precision
);
roundingMin
=
roundingMax
.
negate
();
}
}
}
}
}
src/share/classes/java/math/MutableBigInteger.java
浏览文件 @
364bf2a3
此差异已折叠。
点击以展开。
src/share/classes/java/math/SignedMutableBigInteger.java
浏览文件 @
364bf2a3
...
@@ -129,9 +129,7 @@ class SignedMutableBigInteger extends MutableBigInteger {
...
@@ -129,9 +129,7 @@ class SignedMutableBigInteger extends MutableBigInteger {
* array starting at offset.
* array starting at offset.
*/
*/
public
String
toString
()
{
public
String
toString
()
{
BigInteger
b
=
new
BigInteger
(
this
,
sign
);
return
this
.
toBigInteger
(
sign
).
toString
();
return
b
.
toString
();
}
}
}
}
test/java/math/BigDecimal/AddTests.java
浏览文件 @
364bf2a3
...
@@ -38,6 +38,31 @@ public class AddTests {
...
@@ -38,6 +38,31 @@ public class AddTests {
private
static
Set
<
RoundingMode
>
nonExactRoundingModes
=
private
static
Set
<
RoundingMode
>
nonExactRoundingModes
=
EnumSet
.
complementOf
(
EnumSet
.
of
(
RoundingMode
.
UNNECESSARY
));
EnumSet
.
complementOf
(
EnumSet
.
of
(
RoundingMode
.
UNNECESSARY
));
/**
* Test for some simple additions, particularly, it will test
* the overflow case.
*/
private
static
int
simpleTests
()
{
int
failures
=
0
;
BigDecimal
[]
bd1
=
{
new
BigDecimal
(
new
BigInteger
(
"7812404666936930160"
),
11
),
new
BigDecimal
(
new
BigInteger
(
"7812404666936930160"
),
12
),
new
BigDecimal
(
new
BigInteger
(
"7812404666936930160"
),
13
),
};
BigDecimal
bd2
=
new
BigDecimal
(
new
BigInteger
(
"2790000"
),
1
);
BigDecimal
[]
expectedResult
=
{
new
BigDecimal
(
"78403046.66936930160"
),
new
BigDecimal
(
"8091404.666936930160"
),
new
BigDecimal
(
"1060240.4666936930160"
),
};
for
(
int
i
=
0
;
i
<
bd1
.
length
;
i
++)
{
if
(!
bd1
[
i
].
add
(
bd2
).
equals
(
expectedResult
[
i
]))
failures
++;
}
return
failures
;
}
/**
/**
* Test for extreme value of scale and rounding precision that
* Test for extreme value of scale and rounding precision that
* could cause integer overflow in right-shift-into-sticky-bit
* could cause integer overflow in right-shift-into-sticky-bit
...
...
test/java/math/BigDecimal/DivideTests.java
浏览文件 @
364bf2a3
...
@@ -281,6 +281,10 @@ public class DivideTests {
...
@@ -281,6 +281,10 @@ public class DivideTests {
BigDecimal
c
=
new
BigDecimal
(
"31425"
);
BigDecimal
c
=
new
BigDecimal
(
"31425"
);
BigDecimal
c_minus
=
c
.
negate
();
BigDecimal
c_minus
=
c
.
negate
();
// Ad hoc tests
BigDecimal
d
=
new
BigDecimal
(
new
BigInteger
(
"-37361671119238118911893939591735"
),
10
);
BigDecimal
e
=
new
BigDecimal
(
new
BigInteger
(
"74723342238476237823787879183470"
),
15
);
BigDecimal
[][]
testCases
=
{
BigDecimal
[][]
testCases
=
{
{
a
,
b
,
BigDecimal
.
valueOf
(
ROUND_UP
,
3
),
new
BigDecimal
(
"3.142"
)},
{
a
,
b
,
BigDecimal
.
valueOf
(
ROUND_UP
,
3
),
new
BigDecimal
(
"3.142"
)},
{
a_minus
,
b
,
BigDecimal
.
valueOf
(
ROUND_UP
,
3
),
new
BigDecimal
(
"-3.142"
)},
{
a_minus
,
b
,
BigDecimal
.
valueOf
(
ROUND_UP
,
3
),
new
BigDecimal
(
"-3.142"
)},
...
@@ -305,6 +309,10 @@ public class DivideTests {
...
@@ -305,6 +309,10 @@ public class DivideTests {
{
c
,
b
,
BigDecimal
.
valueOf
(
ROUND_HALF_EVEN
,
3
),
new
BigDecimal
(
"3.142"
)},
{
c
,
b
,
BigDecimal
.
valueOf
(
ROUND_HALF_EVEN
,
3
),
new
BigDecimal
(
"3.142"
)},
{
c_minus
,
b
,
BigDecimal
.
valueOf
(
ROUND_HALF_EVEN
,
3
),
new
BigDecimal
(
"-3.142"
)},
{
c_minus
,
b
,
BigDecimal
.
valueOf
(
ROUND_HALF_EVEN
,
3
),
new
BigDecimal
(
"-3.142"
)},
{
d
,
e
,
BigDecimal
.
valueOf
(
ROUND_HALF_UP
,
-
5
),
BigDecimal
.
valueOf
(-
1
,
-
5
)},
{
d
,
e
,
BigDecimal
.
valueOf
(
ROUND_HALF_DOWN
,
-
5
),
BigDecimal
.
valueOf
(
0
,
-
5
)},
{
d
,
e
,
BigDecimal
.
valueOf
(
ROUND_HALF_EVEN
,
-
5
),
BigDecimal
.
valueOf
(
0
,
-
5
)},
};
};
for
(
BigDecimal
tc
[]
:
testCases
)
{
for
(
BigDecimal
tc
[]
:
testCases
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录