advertisement

advertisement

Information about 1 arithmetic

advertisement

Arithmetic Operations and Functions Operator Operation Fortran Notation + Addition,Unary Plus a+b , +b - Subtraction,Unary Minus a-b , -b * Multiplication a*b / Division a/b Exponentiation a**b ** Eyad Taqieddin 2

Integer Arithmetic Int Int Int Int + Int = Int - Int = Int * Int = Int / Int = Int 5+2=7 5 -2=3 5 * 2 = 10 5 / 2 = 2 why? Division is a special case, because the result must be an integer. So, the fraction part is truncated, and only the integer is stored. Eyad Taqieddin 3

Example what is the result of the following? 1) program example Implicit none Real :: x= 2.0 , y Integer :: n = 2, j y= 1/x j= 1/n print *, ‘y=‘ , y print *, ‘j=‘, j end program example Eyad Taqieddin 4

Priority Rules 1) Parenthesis 2) All exponentiations are performed first, consecutive exponentiations are performed from right to left. 3) All Multiplications and divisions are performed next, in the order in which they appear from left to right. 4) The additions and subtractions are performed last, in the order in which they appear from left to right. Eyad Taqieddin 5

Example 2**3**2 = 2**9 = 512 10-8-2 = 2 – 2 = 0 2+4/2 +5**3 = 2+ 4/2+125=2+2+125 = 129 Eyad Taqieddin 6

Example ((-b) + sqrt( B**2 – 4*a*c))/(2*a) ((-b) + sqrt( B**2 – 4*a*c))/2*a do u think these expressions are equal?? Eyad Taqieddin 7

Mixed Mode Expressions Expressions that involve different types of numeric operands Int + Real = Real Int - Real = Real Int * Real = Real Int / Real = Real The integer value is converted to its real equivalent. Eyad Taqieddin 8

Example 2.0/5 2.0/5.0 0.4 3.0 + 6/4 3.0 + 1 3.0 +1.0 4.0 3.0 + 6.0/4 3.0+ 6.0/4.0 3.0 +1.5 4.5 from the second and third expressions we see why it is not a good programming practice to use mixed mode operations. Eyad Taqieddin 9

Functions Fortran provides library functions for many mathematical operations and functions. Ex: ABS(X) returns the absolute value of X Sqrt(X) returns the square root of X Sin(X) returns the sine of X radians Eyad Taqieddin 10

The Assignment Statement Form Variable = Expression Variable is a valid Fortran identifier. Expression may be a constant, another varialble to which a value has previously been assigned or a formula to be evaluated. Eyad Taqieddin 11

Example Length = 6 assigns the value 6 to the memory location length. C= x**2 + 5*x + 7 calculates the expressions (x**2 + 5*x + 7) and assigns the result to the memory location C. Salary = Salary + 1000 adds the value 1000 to the value stored in the memory location salary and then stores the result in the same memory location. The previous value of salary is lost. Eyad Taqieddin 12

Integer Vs. Real If an integer-valued expression is assigned to a real variable, the integer value is converted to a real constant and then assigned to the variable. temp = (6+2)/4 “assuming temp is real” temp will be assigned the value 2.0 not 2 If a real-valued expression is assigned to an integer variable, the fractional part is truncated and the integer part is assigned to the variable. temp = 2.36 / 2 “assuming temp is integer” temp will be assigned the value 1 not 1.18 Eyad Taqieddin 13

Eine arithmetisch-logische Einheit (englisch arithmetic logic unit, ... Die n-Bit ALU ist meist aus einzelnen 1-Bit-ALUs zusammengesetzt, ...

Read more

Fun math practice! Improve your skills with free problems in 'Arithmetic sequences' and thousands of other practice lessons.

Read more

Arithmetic or arithmetics (from the Greek ... The multiplicative identity is 1, that is, multiplying any number by 1 yields that same number. Also, ...

Read more

3.1 – Arithmetic Operators Lua supports the usual arithmetic operators: the binary `+´ (addition), `-´ (subtraction), `*´ (multiplication ...

Read more

Using delightful themes and full-color illustrations, Arithmetic 1 presents concepts in an orderly manner, building on prior learning and including ...

Read more

1. Arithmetic Ex - Download as PDF File (.pdf), Text File (.txt) or read online.

Read more

Arithmatic synonyms, Arithmatic pronunciation, ... 1. arithmetic - the branch of pure mathematics dealing with the theory of numerical calculations.

Read more

Define arithmetic. arithmetic synonyms, ... 1. arithmetic - the branch of pure mathematics dealing with the theory of numerical calculations. math, ...

Read more

Khan Academy style videos to accompany Mr. Oikawa's scribing lessons. Great as preview or review. All copy-pasted materials are taken from the ...

Read more

## Add a comment