Skip to content
Permalink
Browse files
8285477: Add a PRECISION public static field to j.l.Float and j.l.Double
Reviewed-by: darcy
  • Loading branch information
rgiulietti authored and jddarcy committed Apr 25, 2022
1 parent 1e79ded commit fb605944b5b734c8b47a9122e7ab3d3dcf55f71e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2022, 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
@@ -205,14 +205,30 @@ public final class Double extends Number
*/
public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324

/**
* The number of bits used to represent a {@code double} value.
*
* @since 1.5
*/
public static final int SIZE = 64;

/**
* The number of bits in the significand of a {@code double} value.
* This is the parameter N in section {@jls 4.2.3} of
* <cite>The Java Language Specification</cite>.
*
* @since 19
*/
public static final int PRECISION = 53;

/**
* Maximum exponent a finite {@code double} variable may have.
* It is equal to the value returned by
* {@code Math.getExponent(Double.MAX_VALUE)}.
*
* @since 1.6
*/
public static final int MAX_EXPONENT = 1023;
public static final int MAX_EXPONENT = (1 << (SIZE - PRECISION - 1)) - 1; // 1023

/**
* Minimum exponent a normalized {@code double} variable may
@@ -221,14 +237,7 @@ public final class Double extends Number
*
* @since 1.6
*/
public static final int MIN_EXPONENT = -1022;

/**
* The number of bits used to represent a {@code double} value.
*
* @since 1.5
*/
public static final int SIZE = 64;
public static final int MIN_EXPONENT = 1 - MAX_EXPONENT; // -1022

/**
* The number of bytes used to represent a {@code double} value.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2022, 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
@@ -115,14 +115,30 @@ public final class Float extends Number
*/
public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f

/**
* The number of bits used to represent a {@code float} value.
*
* @since 1.5
*/
public static final int SIZE = 32;

/**
* The number of bits in the significand of a {@code float} value.
* This is the parameter N in section {@jls 4.2.3} of
* <cite>The Java Language Specification</cite>.
*
* @since 19
*/
public static final int PRECISION = 24;

/**
* Maximum exponent a finite {@code float} variable may have. It
* is equal to the value returned by {@code
* Math.getExponent(Float.MAX_VALUE)}.
*
* @since 1.6
*/
public static final int MAX_EXPONENT = 127;
public static final int MAX_EXPONENT = (1 << (SIZE - PRECISION - 1)) - 1; // 127

/**
* Minimum exponent a normalized {@code float} variable may have.
@@ -131,14 +147,7 @@ public final class Float extends Number
*
* @since 1.6
*/
public static final int MIN_EXPONENT = -126;

/**
* The number of bits used to represent a {@code float} value.
*
* @since 1.5
*/
public static final int SIZE = 32;
public static final int MIN_EXPONENT = 1 - MAX_EXPONENT; // -126

/**
* The number of bytes used to represent a {@code float} value.

1 comment on commit fb60594

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.