"O GOD THEE I PRAY INCREASE MY KNOWLEDGE DAY BY DAY"

.

For Success

For Success
Know more than other Work more than other But, Expect less than other

Its a necessary and sufficient condition-----

Its a necessary and sufficient condition-----
"If you win, you need not have to explain.........But if you lose, you should not be there to explain!"

07 October 2010

big airthmetic operation

Airthmetic operations -Addition and subtraction
A simple method to add floating-point numbers is to first represent them with the same exponent. In the example below, the second number is shifted right by three digits, and we then proceed with the usual addition method:
123456.7 = 1.234567 * 10^5
101.7654 = 1.017654 * 10^2 = 0.001017654 * 10^5

Hence:
123456.7 + 101.7654 = (1.234567 * 10^5) + (1.017654 * 10^2)
= (1.234567 * 10^5) + (0.001017654 * 10^5)
= (1.234567 + 0.001017654) * 10^5
= 1.235584654 * 10^5
In detail:
e=5; s=1.234567 (123456.7)
+ e=2; s=1.017654 (101.7654)

e=5; s=1.234567
+ e=5; s=0.001017654 (after shifting)
--------------------
e=5; s=1.235584654 (true sum: 123558.4654)
This is the true result, the exact sum of the operands. It will be rounded to seven digits and then normalized if necessary. The final result is
e=5; s=1.235585 (final sum: 123558.5)
Note that the low 3 digits of the second operand (654) are essentially lost. This is round-off error. In extreme cases, the sum of two non-zero numbers may be equal to one of them:
e=5; s=1.234567
+ e=-3; s=9.876543

e=5; s=1.234567
+ e=5; s=0.00000009876543 (after shifting)
----------------------
e=5; s=1.23456709876543 (true sum)
e=5; s=1.234567 (after rounding/normalization)
Another problem of loss of significance occurs when two close numbers are subtracted. In the following example e = 5; s = 1.234571 and e = 5; s = 1.234567 are representations of the rationals 123457.1467 and 123456.659.
e=5; s=1.234571
- e=5; s=1.234567
----------------
e=5; s=0.000004
e=-1; s=4.000000 (after rounding/normalization)
The best representation of this difference is e = −1; s = 4.877000, which differs more than 20% from e = −1; s = 4.000000. In extreme cases, the final result may be zero even though an exact calculation may be several million. This cancellation illustrates the danger in assuming that all of the digits of a computed result are meaningful. Dealing with the consequences of these errors is a topic in numerical analysis; see also Accuracy problems.
Example: Add 0.1101E02 and 0.1001E05 Step:1 Equalize the exponent—0.1101E02 = 0.0001E05
Step.2 0.0001E05 . . .. …. 0.1001E05 …… 0.1002E05 -- Answer
Ex Example: Add 0.6532E99 and 0.5834E99 Step:1 Equalize the exponent—both exponent’s value are same
Step.2 0.6532E99 . . .. …. 0.5834E99 …… 1.2366E99 = 0.1236E100 = 001.236E99 - overflow condition exponent . . cannot store more than 2 digit
Example: Subtract 0.1101E02 from 0.1001E05 Step:1 Equalize the exponent—0.1101E02 = 0.0001E05
Step.2 0.1001E05 . . .. …. 0.0001E05 …… 0.1000E05---Answer
Ex Example: Subtract 0.6943E-99 from 0.7792E-99 Step:1 Equalize the exponent—both exponent’s value are same
Step.2 0.7792E-99 . . .. …. 0.6943E-99 …… 0.0849E-99 = 0.849E-100 = - underflow condition- exponent .. cannot store more than 2 digit
Multiplication
To multiply, the significands are multiplied while the exponents are added, and the result is rounded and normalized.
e=3; s=4.734612
× e=5; s=5.417242
-----------------------
e=8; s=25.648538980104 (true product)
e=8; s=25.64854 (after rounding)
e=9; s=2.564854 (after normalization)
Ex Example: Multiply 0.1328E03 from 0.6452E10 Step:1 multiply the mantissa----------0.1328 * 0.6452 = 0.08568256
Step.2 multiply the exponent-----E03*E10 =E 13
So answer is -0.8568E13
Ex Example: Multiply 0.7832E54 from 0.2316E51 Step:1 multiply the mantissa----------0.7832 * 0.2316 = 0.181389
Step.2 multiply the exponent-----E54*E51 =E 105
So answer is -0.181389E105-----------Overflow condition- exponent .. cannot store more than 2 digit

Division is done similarly, but is more complicated.
Ex Example: Divide 0.1620E05 by 0.1300E03 Step:1 Shift the dividend to the sufficient number of places to make the mantissa of dividend smaller then the mantissa of divisor-------0.1620 > 0.1300 So 0 .1620E05= 0.0162E06
Step.2 Divide .01620 / 0.1300= 0.1246, reminder = 200
Step-3 subtract the exponent-----E06 - E03 =E03
So answer is-- -0.1246E03
Ex Example: Divide 0.1234E99 by 0.1100E013 Step:1 Shift the dividend to the sufficient number of places to make the mantissa of dividend smaller then the mantissa of divisor-------0.1234 > 0.1100 So 0 .1234E99= 0.0123E100
Step.2 Divide .01230 / 0.1100= 0.1118
Step-3 subtract the exponent-----E100 - E01 =E99
So answer is-- -0.1118E99

There are no cancellation or absorption problems with multiplication or division, though small errors may accumulate as operations are performed repeatedly. In practice, the way these operations are carried out in digital logic can be quite complex (see Booth's multiplication algorithm and digital division). For a fast, simple method, see the Horner method.

No comments:

Post a Comment