Numerical Computing with IEEE Floating Point Arithmetic

Chapter 10: Floating Point in C

The C programming language became very popular in the 1980s. A good reference for the language is [Rob95]. Here we discuss how to get started with floating point computation in C.

Float and Double, Input and Output

In C, the type float normally refers to the IEEE floating point single format, and when we do computations with variables of type float, we say we are using single precision. Here is an echo program that reads in a floating point number using the standard input routine scanf and prints it out again using the standard output routine printf:

main ()     /* Program 1: Echo */{float x;scanf("%f", &x);printf("x = %f", x);}

The second argument to the scanf statement is not the value of the variable x but the address of x; this is the meaning of the & symbol. The address is required because the input routine needs to know where to store the value that is read. On the other hand, the second argument to the printf statement is the value of the variable x. The first argument to both routines is a control string. The two standard format codes used for specifying floating point numbers in these control strings are %f and %e. These refer, respectively, to fixed decimal and exponential decimal formats. Actually, %f and %e have identical effects when used with the input routine scanf

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Rotameters
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.