Variables Arithmetic IO

E teeny tiny fractions most programs do not need

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: values (i.e. teeny-tiny fractions). Most programs do not need extremely large or small values, so very rarely is the fact that computers are finite an issue. However, C++ types also have their limits, and some of these limits need to be considered when writing certain kinds of programs. For any general category of types such as integers, decimal numbers, etc. C++ has multiple specific types that you can choose from to use in your programs. For example, i tis not the only C++ type n that stores integer values. There is also c a , s o t l n , l n l n , and possibly more hr hr, og og og depending on the compiler. As well, d u l is not the only type that can store decimal values. obe There is also f o tand l n d u l . A quick comparison of these types will help you decide la og obe which is appropriate for each variable in your program. Integer types c a can hr store values between -127 and 128 (signed) or between 0 and 255 (unsigned) s o tcan hr store values between -32767 and 32767 (signed) or between 0 and 65535 (unsigned) i tcan n store values between -2147483647 and 2147483647 (signed) or between 0 and 4294967295 l n is the same as i t(on og n l n l n can og og CSE server) store values between -9223372036854775807 and 9223372036854775807 (signed) or between 0 and 18446744073709551615 (unsigned) Decimal ("floating point") types f o tcan la store values up to d u l can obe store values up to l n d u l can og obe store values up to , 6 precision digits are kept , 15 precision digits are kept , 18 precision digits are kept Note about precision in floating point types — The floating point types do not represent values precisely. It is not a good idea to do this: dul x obe ; cn> x i >; i( = 26 / NTGO fx = .) / O OD { / ba.. / lh. } The value 2.6 cannot be represented precisely, so even if the user inputs 2.6, it may not be stored as 2.6. Thus we cannot test if the value is "exactly" 2.6. We must check, instead, if the value is "close" to 2.6, using the following approach: dul x obe ; cn> x i...
View Full Document

Ask a homework question - tutors are online