syque.com

The Psychology of Quality and More

| Menu | Books | Share | Search | Settings |

C Style: Standards and Guidelines (contents)

CHAPTER 9 : Data Usage

PART 4 : USAGE

CHAPTER 9 : Data Usage
9.1 Declarations
9.2 Using floating point numbers
9.3 Using 'typedef'
9.4 Using global data
9.5 Using Structures
9.6 Using Unions
9.7 Using Arrays
9.8 Using Pointers
9.9 Using bit structures
9.10 Using Constants
9.11 Using 'static' declarations
9.12 Initializing variables
9.13 Summary

<--Prev page | Next page -->

 

9.2  Using floating point numbers

Floating point variables should be explicitly kept for floating point numbers. They should never be used where an integer will suffice, as 1.0 does not necessarily equal 1. By the same token, using floating point numbers for loop variables should be avoided, as should any tests for exact value (use >= and <=):

 

if ( Pi != 3.14159)
    printf( "Has Pi been corrupted?\n");

------------------------------------------

float and double are analogous to short and int, in that floats are usually converted to doubles in expressions. Thus if you require limited accuracy or need to save space (eg. in arrays), then use float. Otherwise, and especially if you are unsure of the required accuracy, use double.

 

<--Prev page | Next page -->

 

Site Menu

| Home | Top | Settings |

Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive |

And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact |

Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate |

 

You can buy books here

More Kindle books:

And the big
paperback book


Look inside

 

Please help and share:

 

| Home | Top | Menu |

© Changing Works 2002-2015
Massive Content -- Maximum Speed