Skip to content

FloatingDecimal add final and use record #24999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 9 additions & 27 deletions src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2025, 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
Expand Down Expand Up @@ -34,7 +34,7 @@
* static convenience methods, although a <code>BinaryToASCIIConverter</code>
* instance may be obtained and reused.
*/
public class FloatingDecimal{
public final class FloatingDecimal{
//
// Constants of the implementation;
// most are IEEE-754 related.
Expand Down Expand Up @@ -256,7 +256,7 @@ public boolean decimalDigitsExact() {
/**
* A buffered implementation of <code>BinaryToASCIIConverter</code>.
*/
static class BinaryToASCIIBuffer implements BinaryToASCIIConverter {
static final class BinaryToASCIIBuffer implements BinaryToASCIIConverter {
private boolean isNegative;
private int decExponent;
private int firstDigitIndex;
Expand Down Expand Up @@ -1002,25 +1002,7 @@ interface ASCIIToBinaryConverter {
/**
* A <code>ASCIIToBinaryConverter</code> container for a <code>double</code>.
*/
static class PreparedASCIIToBinaryBuffer implements ASCIIToBinaryConverter {
private final double doubleVal;
private final float floatVal;

public PreparedASCIIToBinaryBuffer(double doubleVal, float floatVal) {
this.doubleVal = doubleVal;
this.floatVal = floatVal;
}

@Override
public double doubleValue() {
return doubleVal;
}

@Override
public float floatValue() {
return floatVal;
}
}
record PreparedASCIIToBinaryBuffer(double doubleValue, float floatValue) implements ASCIIToBinaryConverter {}

static final ASCIIToBinaryConverter A2BC_POSITIVE_INFINITY = new PreparedASCIIToBinaryBuffer(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
static final ASCIIToBinaryConverter A2BC_NEGATIVE_INFINITY = new PreparedASCIIToBinaryBuffer(Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
Expand All @@ -1031,11 +1013,11 @@ public float floatValue() {
/**
* A buffered implementation of <code>ASCIIToBinaryConverter</code>.
*/
static class ASCIIToBinaryBuffer implements ASCIIToBinaryConverter {
boolean isNegative;
int decExponent;
byte[] digits;
int nDigits;
static final class ASCIIToBinaryBuffer implements ASCIIToBinaryConverter {
final boolean isNegative;
final int decExponent;
final byte[] digits;
int nDigits;

ASCIIToBinaryBuffer( boolean negSign, int decExponent, byte[] digits, int n)
{
Expand Down