6964528: Double.toHexString(double d) String manipulation with + in an append of StringBuilder
Reviewed-by: shade
This commit is contained in:
parent
854e269f20
commit
0050c5b4fb
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -289,7 +289,7 @@ public final class Double extends Number implements Comparable<Double> {
|
|||||||
return Double.toString(d);
|
return Double.toString(d);
|
||||||
else {
|
else {
|
||||||
// Initialized to maximum size of output.
|
// Initialized to maximum size of output.
|
||||||
StringBuffer answer = new StringBuffer(24);
|
StringBuilder answer = new StringBuilder(24);
|
||||||
|
|
||||||
if (Math.copySign(1.0, d) == -1.0) // value is negative,
|
if (Math.copySign(1.0, d) == -1.0) // value is negative,
|
||||||
answer.append("-"); // so append sign info
|
answer.append("-"); // so append sign info
|
||||||
@ -300,8 +300,7 @@ public final class Double extends Number implements Comparable<Double> {
|
|||||||
|
|
||||||
if(d == 0.0) {
|
if(d == 0.0) {
|
||||||
answer.append("0.0p0");
|
answer.append("0.0p0");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
|
boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
|
||||||
|
|
||||||
// Isolate significand bits and OR in a high-order bit
|
// Isolate significand bits and OR in a high-order bit
|
||||||
@ -324,13 +323,14 @@ public final class Double extends Number implements Comparable<Double> {
|
|||||||
"0":
|
"0":
|
||||||
signif.replaceFirst("0{1,12}$", ""));
|
signif.replaceFirst("0{1,12}$", ""));
|
||||||
|
|
||||||
|
answer.append('p');
|
||||||
// If the value is subnormal, use the E_min exponent
|
// If the value is subnormal, use the E_min exponent
|
||||||
// value for double; otherwise, extract and report d's
|
// value for double; otherwise, extract and report d's
|
||||||
// exponent (the representation of a subnormal uses
|
// exponent (the representation of a subnormal uses
|
||||||
// E_min -1).
|
// E_min -1).
|
||||||
answer.append("p" + (subnormal ?
|
answer.append(subnormal ?
|
||||||
DoubleConsts.MIN_EXPONENT:
|
DoubleConsts.MIN_EXPONENT:
|
||||||
Math.getExponent(d) ));
|
Math.getExponent(d));
|
||||||
}
|
}
|
||||||
return answer.toString();
|
return answer.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user