Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Floating point variables

Node:Floating point variables, Previous:The char type, Up:Integer variables



Floating point variables

Floating point numbers are numbers with a decimal point. There are different sizes of floating point numbers in C. The float type can contain large floating point numbers with a small degree of precision, but the double-precision double type can hold even larger numbers with a higher degree of precision. (Precision is simply the number of decimal places to which a number can be computed with accuracy. If a number can be computed to five decimal places, it is said to have five significant digits.)

All floating point mathematical functions built into C require double or long float arguments (long float variables are generally the same as double variables on GNU systems), so it is common to use float only for storage of small floating point numbers, and to use double everywhere else.

Here are the floating point variable types available in C:

  • float: A single-precision floating point number, with at least 6 significant decimal digits.
  • double: A double-precision floating point number. Usually the same as long float on GNU systems. Has at least 10 significant decimal digits.
  • long double: Usually the same as double on GNU systems, but may be a 128-bit number in some cases.

On a typical 32-bit GNU system, the sizes of the different floating point types are as follows.

Type Bits Possible values (approx.)
float 32 1e-38 to 1e+38
double 64 2e-308 to 1e+308
long double 64 2e-308 to 1e+308


You may find the figures in the right-hand column confusing. They use a form of shorthand for large numbers. For example, the number 5e2 means 5 * 10^2, or 500. 5e-2 means 5 * 10^-2 (5/100, or 1/20). You can see, therefore, that the float, double, and long double types can contain some very large and very small numbers indeed. (When you work with large and small numbers in C, you will use this notation in your code.)

 
 
  Published under free license. Design by Interspire