mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8369312: Refactor Float.toHexString() to avoid use of regex
Reviewed-by: rgiulietti
This commit is contained in:
parent
64ff7062c1
commit
7ed93cf40e
@ -420,10 +420,12 @@ public final class Float extends Number
|
||||
// replace subnormal double exponent with subnormal float
|
||||
// exponent
|
||||
String s = Double.toHexString(Math.scalb((double)f,
|
||||
/* -1022+126 */
|
||||
Double.MIN_EXPONENT-
|
||||
// -1022 + 126
|
||||
Double.MIN_EXPONENT -
|
||||
Float.MIN_EXPONENT));
|
||||
return s.replaceFirst("p-1022$", "p-126");
|
||||
// The char sequence "-1022" can only appear in the
|
||||
// representation of the exponent, not in the (hex) significand.
|
||||
return s.replace("-1022", "-126");
|
||||
}
|
||||
else // double string will be the same as float string
|
||||
return Double.toHexString(f);
|
||||
|
||||
@ -295,10 +295,12 @@ public final class Float16
|
||||
// replace subnormal double exponent with subnormal Float16
|
||||
// exponent
|
||||
String s = Double.toHexString(Math.scalb((double)f,
|
||||
/* -1022+14 */
|
||||
Double.MIN_EXPONENT-
|
||||
// -1022 + 14
|
||||
Double.MIN_EXPONENT -
|
||||
MIN_EXPONENT));
|
||||
return s.replaceFirst("p-1022$", "p-14");
|
||||
// The char sequence "-1022" can only appear in the
|
||||
// representation of the exponent, not in the (hex) significand.
|
||||
return s.replace("-1022", "-14");
|
||||
} else {// double string will be the same as Float16 string
|
||||
return Double.toHexString(f);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user