Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
314446a4
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看板
提交
314446a4
编写于
4月 03, 2019
作者:
I
igerasim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8211936: Better String parsing
Reviewed-by: aph
上级
1fb3e237
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
11 deletion
+39
-11
src/share/classes/java/math/BigDecimal.java
src/share/classes/java/math/BigDecimal.java
+39
-11
未找到文件。
src/share/classes/java/math/BigDecimal.java
浏览文件 @
314446a4
/*
* Copyright (c) 1996, 201
8
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 201
9
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -3060,9 +3060,32 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
* @return this {@code BigDecimal} converted to a {@code long}.
*/
public
long
longValue
(){
return
(
intCompact
!=
INFLATED
&&
scale
==
0
)
?
intCompact:
toBigInteger
().
longValue
();
if
(
intCompact
!=
INFLATED
&&
scale
==
0
)
{
return
intCompact
;
}
else
{
// Fastpath zero and small values
if
(
this
.
signum
()
==
0
||
fractionOnly
()
||
// Fastpath very large-scale values that will result
// in a truncated value of zero. If the scale is -64
// or less, there are at least 64 powers of 10 in the
// value of the numerical result. Since 10 = 2*5, in
// that case there would also be 64 powers of 2 in the
// result, meaning all 64 bits of a long will be zero.
scale
<=
-
64
)
{
return
0
;
}
else
{
return
toBigInteger
().
longValue
();
}
}
}
/**
* Return true if a nonzero BigDecimal has an absolute value less
* than one; i.e. only has fraction digits.
*/
private
boolean
fractionOnly
()
{
assert
this
.
signum
()
!=
0
;
return
(
this
.
precision
()
-
this
.
scale
)
<=
0
;
}
/**
...
...
@@ -3080,15 +3103,20 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
public
long
longValueExact
()
{
if
(
intCompact
!=
INFLATED
&&
scale
==
0
)
return
intCompact
;
// If more than 19 digits in integer part it cannot possibly fit
if
((
precision
()
-
scale
)
>
19
)
// [OK for negative scale too]
throw
new
java
.
lang
.
ArithmeticException
(
"Overflow"
);
// Fastpath zero and < 1.0 numbers (the latter can be very slow
// to round if very small)
// Fastpath zero
if
(
this
.
signum
()
==
0
)
return
0
;
if
((
this
.
precision
()
-
this
.
scale
)
<=
0
)
// Fastpath numbers less than 1.0 (the latter can be very slow
// to round if very small)
if
(
fractionOnly
())
throw
new
ArithmeticException
(
"Rounding necessary"
);
// If more than 19 digits in integer part it cannot possibly fit
if
((
precision
()
-
scale
)
>
19
)
// [OK for negative scale too]
throw
new
java
.
lang
.
ArithmeticException
(
"Overflow"
);
// round to an integer, with Exception if decimal part non-0
BigDecimal
num
=
this
.
setScale
(
0
,
ROUND_UNNECESSARY
);
if
(
num
.
precision
()
>=
19
)
// need to check carefully
...
...
@@ -3130,7 +3158,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
public
int
intValue
()
{
return
(
intCompact
!=
INFLATED
&&
scale
==
0
)
?
(
int
)
intCompact
:
toBigInteger
().
int
Value
();
(
int
)
long
Value
();
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录