chapter 11 additional intrinsic data types dr. ali can takinacı İstanbul technical university...

14
Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel: +90 (212 285 6519) Fax: +90 (212 285 6508) E-mail: [email protected]

Post on 21-Dec-2015

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Chapter 11 Additional Intrinsic Data

Types

Dr. Ali Can Takinacıİstanbul Technical University

Faculty of Naval Architecture and Ocean Engineeringİstanbul - Turkey

Tel: +90 (212 285 6519) Fax: +90 (212 285 6508) E-mail: [email protected]

Page 2: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Intrinsic Data Types

ALTERNATIVE KINDS OF THE REAL DATA TYPE

•For traditional reasons, the shorter version of the REAL data type on any particular computer is known as single precision, and the longer version of the REA L data type on any particular computer is known as double precision. •On most computers, a single-precision real value is stored in 32 bits, and a double-precision real value is stored in 64 bits. •However, some 64-bit processors use 64 bits for single •precision and 128 bits for double precision.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 2

Page 3: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

Kinds of REAL Constants and Variables

•Since Fortran compilers have at least two different kinds of real variables, there must be some way to declare which of the types we want to use in a particular problem. •This is done by using a kind type parameter. •Single-precision reals and double-precision reals are different kinds of the REA L data type, each with its own unique kind number.

•In addition to the previous examples, a double-precision constant in exponential notation can be declared by using a D instead of an E to declare the exponent of the constant. For example,

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 3

Page 4: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

•Example: Program in Silverfrost

•Gives the output screen

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 4

Page 5: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

Determining the KIND of a Variable

•Fortran 95 includes an intrinsic function KIND, which returns the kind number of a given constant or variable. •This function can be used to determine the kind numbers in use by your compiler.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 5

Page 6: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

THE COMPLEX DATA TYPE

•Complex numbers occur in many problems in science and engineering. •For example, complex numbers are used in electrical engineering to represent alternating current voltages, currents, and impedances.•The differential equations that describe the behavior of most electrical and mechanical systems also give rise to complex numbers. •Because they are so ubiquitous, it is impossible to work as an engineer without a good understanding of the use and manipulation of complex numbers.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 6

Page 7: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures© 2010, Dr. ALİ CAN TAKİNACI Slide No: 7

Page 8: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures© 2010, Dr. ALİ CAN TAKİNACI Slide No: 8

Page 9: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

Complex Constants and Variables

•A complex constant consists of two numeric constants separated by commas and enclosed in parentheses. •The first constant is the real part of the complex number, and •the second constant is the imaginary part of the complex number. •For example, the following complex constants are equivalent to the complex numbers shown next to them:

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 9

Page 10: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

•A complex variable is declared by using a COMPLEX type declaration statement. •The form of this statement is

•The kind of the complex variable is optional; if it is left out the default kind will be used. •For example, the following statement declares a 256 element complex array. •Remember that we are actually allocating 512 default-length values, since two real values are required for each complex number.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 10

Page 11: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

Initializing Complex Variables

•Like other variables, complex variables may be initialized by assignment statements, in type declaration statements, or by READ statements.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 11

Page 12: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

Using Complex Numbers with Relational Operators

•It is possible to compare two complex numbers with the == relational operator to see if they are equal to each other, and to compare them with the /= operator to see if they are not equal to each other. •However, they cannot be compared with the >, <, >=, or <= operators. •The reason for this is that complex numbers consist of two separate parts.•Suppose that we have two complex numbers c1 = a1 + b1i and c2 = a2 + b2 i, •with a1 > a2 and b1 < b2 . •How can we possibly say which of these numbers is larger?

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 12

Page 13: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

COMPLEX Intrinsic Functions

•1. Type conversion functions. These functions convert data to and from the complex data type. •Function CMPLX(a, b) is a generic function that converts real or integer numbers a and b into a complex number whose real part has value a and whose imaginary part has value b. •Functions REAL( ) and INT( ) convert the real part of a complex number into the corresponding real or integer data type, and throwaway the imaginary part of the complex •number. •Function AIMAG( ) converts the imaginary part of a complex number into a real number.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 13

Page 14: Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul

Additional Features of Procedures

•2. Absolute value function. This function calculates the absolute value of a number. •Function CABS(c) is a specific function that calculates the absolute value of a complex number, using the equation

•3. Mathematical functions. These functions include exponential functions, logarithms, trigonometric functions, and square roots. •The generic functions SIN, COS, LOG10, SQRT, etc. will work as well with complex data as they will with real data.

© 2010, Dr. ALİ CAN TAKİNACI Slide No: 14