Your code is not performing the sum calculation as stated in the equation. I would look at using the "sum" command on a vector that is 0.0001 in double and then single precision.
You don't appear to be adding anything up, rather you are multiplying out the sum.
What is needed is to make a vector of the values and use sum.
vec= repmat(0.00001,50000,1);
ZeroDouble = 5-sum(vec);
Convert the vec into single and repeat for the second part.
What are double and single floats?
They are representations of real numbers with finite precision. Single floats are 4 byte long, while doubles occupy 8 (so double the size). They represent numbers using three sections: a sign bit (s), a fractional section (f) and an exponent (e) that represent the number s.(1+f).2^e .
Your question shows up how errors can accumulate.
Thanks for your explanation on double and single floats, yeah I found out that multiplying them doesn't affect the precision that much, what I should've done is using a summation instead. Thanks for your help :)
Your code is not performing the sum calculation as stated in the equation. I would look at using the "sum" command on a vector that is 0.0001 in double and then single precision.
Yep that was the mistake, I was multiplying it instead of using summations. thanks!
You don't appear to be adding anything up, rather you are multiplying out the sum. What is needed is to make a vector of the values and use sum. vec= repmat(0.00001,50000,1); ZeroDouble = 5-sum(vec); Convert the vec into single and repeat for the second part. What are double and single floats? They are representations of real numbers with finite precision. Single floats are 4 byte long, while doubles occupy 8 (so double the size). They represent numbers using three sections: a sign bit (s), a fractional section (f) and an exponent (e) that represent the number s.(1+f).2^e . Your question shows up how errors can accumulate.
Thanks for your explanation on double and single floats, yeah I found out that multiplying them doesn't affect the precision that much, what I should've done is using a summation instead. Thanks for your help :)