If fx 2x1 1x2 11x is computed in flarithmetic by the formul

If f(x) = (2x+1)/( 1x^2) (1/1+x) is computed in fl-arithmetic by the formula (2.0 x + 1.0)/(1.0 x x) 1.0/(1.0 + x) then there will be a loss of precision for x close to zero. Explain why. Propose an algorithm for computing f(x) that will produce small relative error for x close to zero.

Solution

Given formula:

(2.0 x + 1.0)/(1.0 x x) 1.0/(1.0 + x)

in the above formula, x is type int, so it need to be converted into float ,while evaluating the above formula, this leads to a loss of precision means loss of least significant bits..this occurs because the result floating point value..(float value).. is the rounded result of integer value...

convertion of int to float... will lead to a loss of precision ..

to avoid this we need to convert to double.. because this will never lead to loss of precision..(52 bits in its fraction)

so..

the algorithm with out loss of precision is..

(2.0 (double)x + 1.0)/(1.0 (double)x (double)x) 1.0/(1.0 + (double)x)

If f(x) = (2x+1)/( 1x^2) (1/1+x) is computed in fl-arithmetic by the formula (2.0 x + 1.0)/(1.0 x x) 1.0/(1.0 + x) then there will be a loss of precision for x

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site