CS 200 - Lab 3

Floating-point imprecision

Test the claim that the number 0.1 (one tenth) cannot be represented exactly as a floating-point value.

You should write a program that uses the printf function to print the literal floating-point value 0.1 to a sufficent number of decimal places that you can see that it does not equal precisely 0.1.

Getting started

Start by downloading lab3.zip and using the File->Import... menu option to import it into VIsual Studio.  Add your code to the source file DecimalPlaces.c.

You are done when you prove it is possible to print the literal value 0.1 and show that it does not equal 0.1.

Hints

As a literal, 0.1 is a value whose type is double.

Use the %f conversion specifier to print the value.  Use the formatting option which specifies the number of digits of precision: e.g., to print two digits after the decimal place, you would use the conversion specifier

%.2f

Note that you can specify more than 9 digits of precision.

Question: what is the smallest number of digits of precision you need to show that the value is not equal to 0.1?