, ,

The Floating-Point Types – Basic Elements, Primitive Data Types, and Operators

The Floating-Point Types

Floating-point numbers are represented by the float and double data types.

Floating-point numbers conform to the IEEE 754-1985 binary floating-point standard. Table 2.14 shows the range of values for positive floating-point numbers, but these apply equally to negative floating-point numbers with the minus sign (-) as a prefix. Zero can be either 0.0 or -0.0. The range of values represented by the double data type is wider than that of the float data type.

Table 2.14 Range of Floating-Point Values

Since the size for representation is a finite number of bits, certain floating-point numbers can be represented only as approximations. For example, the value of the expression (1.0/3.0) is represented as an approximation due to the finite number of bits used to represent floating-point numbers.

The boolean Type

The data type boolean represents the two logical values denoted by the literals true and false (Table 2.15).

Table 2.15 Boolean Values

Data typeWidthTrue value literalFalse value literal
booleanNot applicabletruefalse

Boolean values are results of all relational (p. 74), conditional (p. 80), and boolean (p. 78) logical operators.

Table 2.16 summarizes the pertinent facts about the primitive data types: their width or size, which indicates the number of bits required to store a primitive value; their range of legal values, which is specified by the minimum and maximum values permissible; and the name of the corresponding wrapper class (§8.3, p. 429).

Table 2.16 Summary of Primitive Data Types

Data typeWidth (bits)Minimum value, maximum valueWrapper class
booleanNot applicabletrue, falseBoolean
byte8–27, 27 – 1Byte
short16–215, 215 – 1Short
char160x0, 0xffffCharacter
int32–231, 231 – 1Integer
long64–263, 263 – 1Long
float32±1.40129846432481707e-45f, ±3.402823476638528860e+38fFloat
double64±4.94065645841246544e-324, ±1.79769313486231570e+308Double
Related Posts