15
n” The compiler recognizes both '\n' and “\n” as containing the newline character. The difference is in the data type used. Formally, '\n' is a character literal, and “\n” is a string literal. From a practical standpoint, both cause the same thing to happen: A new line is forced in the output display.

More on Data Types (Exponential and Scientific Notations)

Embed Size (px)

Citation preview

Page 1: More on Data Types (Exponential and Scientific Notations)

The Character '\n' and the String “\n”

The compiler recognizes both '\n' and “\n” as containing the newline character. The difference is in the data type used. Formally, '\n' is a character literal, and “\n” is a string literal. From a practical standpoint, both cause the same thing to happen: A new line is forced in the output display.

Page 2: More on Data Types (Exponential and Scientific Notations)

Good programming practice requires ending the last output display with a newline escape sequence. This practice ensures that the first line of output from one program doesn’t end up on the last line displayed by the previously executed program.

Page 3: More on Data Types (Exponential and Scientific Notations)

A signed data type allows storing negative values, the value 0, and positive values

An unsigned data type provides for only non-negative values (that is, 0 and positive values). Some applications require only unsigned numerical values.

Page 4: More on Data Types (Exponential and Scientific Notations)

For example, many date applications store dates in the numerical form yearmonthday (storing 12/25/2011 as 20111225, for example)

For these applications, which never require a negative value, an unsigned data type can be used.

Page 5: More on Data Types (Exponential and Scientific Notations)
Page 6: More on Data Types (Exponential and Scientific Notations)

Floating-Point Types

A floating-point number, more commonly known as a real number, can be the number 0 or any positive or negative number containing a decimal point. The following are examples of floating point numbers:

+10.62 5.0 -6.2 3251.92 0.00 .33-6.67 +2.

Page 7: More on Data Types (Exponential and Scientific Notations)

A float value is sometimes referred to as a single-precision number and a double value as a double-precision number. 9.234 indicates a double literal.

9.234F indicates a float literal.

9.234L indicates a long double literal.

Page 8: More on Data Types (Exponential and Scientific Notations)

What is precision?

In numerical theory, the term precision typically refers to numerical accuracy.

Page 9: More on Data Types (Exponential and Scientific Notations)

“This computation is accurate, or precise, to the fifth decimal place” means the fifth digit after the decimal point has been rounded, and the number is accurate to within ±0.00005.

Page 10: More on Data Types (Exponential and Scientific Notations)

687.45678921 has five significant digits therefore; its accurate to have the value 687.46. The last digit assumed to be rounded.

Page 11: More on Data Types (Exponential and Scientific Notations)

In computer programming, “precision” can refer to a number’s accuracy or the number of significant digits; significant digits are defined as the number of clearly correct digits plus 1.

Page 12: More on Data Types (Exponential and Scientific Notations)

.000734 7.34e-4

7.34x10

-4.000000000954

Is it big number? Why?

67598934 6.7598934e7

6.7598934x107

Page 13: More on Data Types (Exponential and Scientific Notations)

Exponential Notation

Floating-point numbers can also be written in exponential notation, which is similar to scientific notation and is commonly used to express both very large and very small values in compact form. The following examples show how numbers with decimals can be expressed in exponential and scientific notation:

Page 14: More on Data Types (Exponential and Scientific Notations)
Page 15: More on Data Types (Exponential and Scientific Notations)