RFR: 8343829: Unify decimal and hexadecimal parsing in FloatingDecimal [v3]
j3graham
duke at openjdk.org
Sun Dec 15 21:59:36 UTC 2024
On Fri, 13 Dec 2024 16:06:53 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> See the JBS bug for some details.
>
> Raffaello Giulietti has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
>
> - Merge branch 'master' into 8343829
> - Minors in comments.
> - Removed repeated comment.
> - Refactoring some code and comments.
> - 8343829: Unify decimal and hexadecimal parsing in FloatingDecimal
src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java line 2354:
> 2352:
> 2353: /* The precision of the format. */
> 2354: private static final int[] P = {
What about organizing these constants as as a record - something like this:
record FloatFmt(int ix, int p, int epMin, int epMax, int w, int eMin, int eMax, int qMin, int hexCount) {
public static final FloatFmt BINARY_16 = build(0, 11, -8, 6);
public static final FloatFmt BINARY_32 = build(1, 24, -46, 40);
public static final FloatFmt BINARY_64 = build(2, 53, -324, 310);
public static final FloatFmt BINARY_128 = build(3, 113, -4_966, 4934);
public static final FloatFmt BINARY_256 = build(4, 237, -78_985, 78_915);
private static FloatFmt build(int ix, int p, int epMin, int epMax) {
int w = (1 << 4 + ix) - p;
int eMin = (-1 << w - 1) + 2;
int eMax = (1 << w - 1) - 1;
int qMin = eMin - p + 1;
int hexCount = p / 4 + 2;
return new FloatFmt(ix, p, epMin, epMax, w, eMin, eMax, qMin, hexCount);
}
}
Methods could then be parameterized with the static instances rather than integers. I believe these values would inline well as constants.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22737#discussion_r1885896862
More information about the core-libs-dev
mailing list