---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 13 Edition"
java_version: 13
chapter: "Chapter 4. Types, Values, and Variables"
section: "4.2.3"
heading: "4.2.3. Floating-Point Types, Formats, and Values"
parent: "4.2. Primitive Types and Values"
source: https://docs.oracle.com/javase/specs/jls/se13/html/jls-4.html#jls-4.2.3
id: "4.2.3"
url: https://jvm.obfuscated.software/jls/se13/4.2.3.html
raw: https://jvm.obfuscated.software/jls/se13/4.2.3.md
---

# 4.2.3. Floating-Point Types, Formats, and Values

The floating-point types are `float` and `double`, which are conceptually associated with the single-precision 32-bit and double-precision 64-bit format IEEE 754 values and operations as specified in *IEEE Standard for Binary Floating-Point Arithmetic*, ANSI/IEEE Standard 754-1985 (IEEE, New York).

The IEEE 754 standard includes not only positive and negative numbers that consist of a sign and magnitude, but also positive and negative zeros, positive and negative *infinities*, and special *Not-a-Number* values (hereafter abbreviated NaN). A NaN value is used to represent the result of certain invalid operations such as dividing zero by zero. NaN constants of both `float` and `double` type are predefined as `Float.NaN` and `Double.NaN`.

Every implementation of the Java programming language is required to support two standard sets of floating-point values, called the *float value set* and the *double value set*. In addition, an implementation of the Java programming language may support either or both of two extended-exponent floating-point value sets, called the *float-extended-exponent value set* and the *double-extended-exponent value set*. These extended-exponent value sets may, under certain circumstances, be used instead of the standard value sets to represent the values of expressions of type `float` or `double` ([§5.1.13](5.1.13.md), [§15.4](15.4.md)).

The finite nonzero values of any floating-point value set can all be expressed in the form *s* ⋅ *m* ⋅ 2^{(e - N + 1)}, where *s* is +1 or -1, *m* is a positive integer less than 2^N, and *e* is an integer between *E_{min}* = -(2^{K-1}-2) and *E_{max}* = 2^{K-1}-1, inclusive, and where *N* and *K* are parameters that depend on the value set. Some values can be represented in this form in more than one way; for example, supposing that a value *v* in a value set might be represented in this form using certain values for *s*, *m*, and *e*, then if it happened that *m* were even and *e* were less than 2^{K-1}, one could halve *m* and increase *e* by 1 to produce a second representation for the same value *v*. A representation in this form is called *normalized* if *m* ≥ 2^{N-1}; otherwise the representation is said to be *denormalized*. If a value in a value set cannot be represented in such a way that *m* ≥ 2^{N-1}, then the value is said to be a *denormalized value*, because it has no normalized representation.

The constraints on the parameters *N* and *K* (and on the derived parameters *E_{min}* and *E_{max}*) for the two required and two optional floating-point value sets are summarized in Table 4.2.3-A.

**Table 4.2.3-A. Floating-point value set parameters**

| Parameter | float | float-extended-exponent | double | double-extended-exponent |
|---|---|---|---|---|
| *N* | 24 | 24 | 53 | 53 |
| *K* | 8 | ≥ 11 | 11 | ≥ 15 |
| *E_{max}* | +127 | ≥ +1023 | +1023 | ≥ +16383 |
| *E_{min}* | -126 | ≤ -1022 | -1022 | ≤ -16382 |

Where one or both extended-exponent value sets are supported by an implementation, then for each supported extended-exponent value set there is a specific implementation-dependent constant *K*, whose value is constrained by Table 4.2.3-A; this value *K* in turn dictates the values for *E_{min}* and *E_{max}*.

Each of the four value sets includes not only the finite nonzero values that are ascribed to it above, but also NaN values and the four values positive zero, negative zero, positive infinity, and negative infinity.

Note that the constraints in Table 4.2.3-A are designed so that every element of the float value set is necessarily also an element of the float-extended-exponent value set, the double value set, and the double-extended-exponent value set. Likewise, each element of the double value set is necessarily also an element of the double-extended-exponent value set. Each extended-exponent value set has a larger range of exponent values than the corresponding standard value set, but does not have more precision.

The elements of the float value set are exactly the values that can be represented using the single floating-point format defined in the IEEE 754 standard. The elements of the double value set are exactly the values that can be represented using the double floating-point format defined in the IEEE 754 standard. Note, however, that the elements of the float-extended-exponent and double-extended-exponent value sets defined here do *not* correspond to the values that can be represented using IEEE 754 single extended and double extended formats, respectively.

The float, float-extended-exponent, double, and double-extended-exponent value sets are not types. It is always correct for an implementation of the Java programming language to use an element of the float value set to represent a value of type `float`; however, it may be permissible in certain regions of code for an implementation to use an element of the float-extended-exponent value set instead. Similarly, it is always correct for an implementation to use an element of the double value set to represent a value of type `double`; however, it may be permissible in certain regions of code for an implementation to use an element of the double-extended-exponent value set instead.

Except for NaN, floating-point values are *ordered*; arranged from smallest to largest, they are negative infinity, negative finite nonzero values, positive and negative zero, positive finite nonzero values, and positive infinity.

IEEE 754 allows multiple distinct NaN values for each of its single and double floating-point formats. While each hardware architecture returns a particular bit pattern for NaN when a new NaN is generated, a programmer can also create NaNs with different bit patterns to encode, for example, retrospective diagnostic information.

For the most part, the Java SE Platform treats NaN values of a given type as though collapsed into a single canonical value, and hence this specification normally refers to an arbitrary NaN as though to a canonical value.

However, version 1.3 of the Java SE Platform introduced methods enabling the programmer to distinguish between NaN values: the `Float.floatToRawIntBits` and `Double.doubleToRawLongBits` methods. The interested reader is referred to the specifications for the `Float` and `Double` classes for more information.

Positive zero and negative zero compare equal; thus the result of the expression `0.0==-0.0` is `true` and the result of `0.0>-0.0` is false. But other operations can distinguish positive and negative zero; for example, `1.0/0.0` has the value positive infinity, while the value of `1.0/-0.0` is negative infinity.

NaN is *unordered*, so:

- The numerical comparison operators `<`, `<=`, `>`, and `>=` return `false` if either or both operands are NaN ([§15.20.1](15.20.1.md)).

  In particular, `(x<y) == !(x>=y)` will be `false` if `x` or `y` is NaN.

- The equality operator `==` returns `false` if either operand is NaN.

- The inequality operator `!=` returns `true` if either operand is NaN ([§15.21.1](15.21.1.md)).

  In particular, `x!=x` is `true` if and only if `x` is NaN.
