Previous: 5.1.1 Signed and Unsigned Integer Types
Up: 5.1 Representing Numbers
Previous Page: 5.1.1 Signed and Unsigned Integer Types
Next Page: 5.2 New Control Constructs

5.1.2 Single and Double Precision Floating Point Numbers

Different sizes of floating point data can also be declared with the keywords float and double. The type specifier double is used to declare double precision floating point numbers. The size of float is typically 32 bits, and that of double is 64 bits. For greater precision, most scientific and engineering computation should be performed using the double data type. Furthermore, extra precision may be provided for floating point numbers by declaring them long double. (This may be the same as or more bits of precision as double, depending on implementation). Here are example declarations for floating point numbers:

float  x;
     double GPR;
     long double y;

Decimal float constants in programs have an integer part and a fractional part with a decimal point between them. They may also be written in scientific (or exponential) notation, i.e. a decimal number multiplied by a power of ten to indicate the actual position of the decimal point. Positive and negative numbers may be written with an explicit positive or negative unary operator.

123.789
     0.5534
     +9635.0000
     -8942.3214
     -0.765E5
     1.4523e12
     0.786345e-10
The last three numbers are written in exponential notation with the exponent of ten shown after the letter e or E. The exponent may be a positive or a negative integer. For clarity, always write float numbers with at least one digit before and one after the decimal point; for example, zero is 0.0 in float representation.

Floating point constants are taken to be of double precision type by default. Single precision floating point constants may be specified with a suffix f or F.

34.567f
     3.141516F
Extra precision for constants may be written with the suffix l or L:
23456789.171819L



Previous: 5.1.1 Signed and Unsigned Integer Types
Up: 5.1 Representing Numbers
Previous Page: 5.1.1 Signed and Unsigned Integer Types
Next Page: 5.2 New Control Constructs

tep@wiliki.eng.hawaii.edu
Wed Aug 17 08:40:40 HST 1994