# absolute and relative error

• Aug 31st 2008, 12:17 AM
syner
absolute and relative error
Hey just need some help with absolute and relative errors

q) find the absolute and relative error when a computer stores 2/3 (two thirds)

q2)then calculate the absolute and relative error when a computer adds
2/3 + 2/3 + 2/3 (two thirds + two thirds + two thirds)

• Aug 31st 2008, 11:50 PM
CaptainBlack
Quote:

Originally Posted by syner
Hey just need some help with absolute and relative errors

q) find the absolute and relative error when a computer stores 2/3 (two thirds)

In binary:

$\displaystyle \frac{2}{3}=0b10101010101....$

Now how many bits do you have in the mantissa? If you are using normalized floating point you will have an extra bit of precision.

So if we have a 23 bit mantissa we have 24 bits of precision so our floating point representation of $\displaystyle 2/3$ is:

$\displaystyle u=0b101010101010101010101010$

So the error is $\displaystyle \varepsilon=(2/3) 2^{-24}$

(If the representation rounds rather than truncates then:

$\displaystyle u=0b101010101010101010101011$

and you will need to recompute the exact error)

RonL
• Sep 1st 2008, 03:35 AM
syner
Oh ok, what was the algorithm (method) that you used to get the binary result of $\displaystyle 2/3$ ? (two over three)
and also the algorithm that you used to get the final results etc? sorry just trying to learn this stuff
• Sep 1st 2008, 05:25 AM
CaptainBlack
Quote:

Originally Posted by syner
Oh ok, what was the algorithm (method) that you used to get the binary result of $\displaystyle 2/3$ ? (two over three)
and also the algorithm that you used to get the final results etc? sorry just trying to learn this stuff

No explicit algorithm I just expanded it using the definition of a binary fraction, whuich could be considered a/the greedy algorithm. Then truncating at the effective number of bits.

RonL
• Sep 1st 2008, 06:01 PM
syner
Lol surley there must be some sort of way that you worked out the binary.

I know how to work from binary to hex, vice versa, floating point representation (now after abit of study)

but this is the one bit that i am stumped at, what working did you use to get the binary value?

Lol still abit lost to how i figure out the relative and absolute error, sorry i think i suffer from maths dislexia
• Sep 1st 2008, 08:35 PM
CaptainBlack
Quote:

Originally Posted by syner
Lol surley there must be some sort of way that you worked out the binary.

I know how to work from binary to hex, vice versa, floating point representation (now after abit of study)

but this is the one bit that i am stumped at, what working did you use to get the binary value?

Lol still abit lost to how i figure out the relative and absolute error, sorry i think i suffer from maths dislexia

Greedy algorithm:

Code:

x: real <1  //input is a real less than 1 max=24    //number of bits required   out=""      //set output to null string   for idx=1 to max   if x>=1/2          //if x>=1/2 tag a 1 onto end of output string     out=out|"1"    //and reduce x by 1/2     x=x-1/2   else     out=out|"0"    //if x<1/2 tag a 0 onto end of output string   endif endfor   return out
RonL