What is a simple example of floating point/rounding error?
c++, floating-accuracy
Solution
Picture is worth a thousand words - try to draw equation `f(k)` : and you will get such XY graph (X and Y are in logarithmic scale). If computer could represent 32-bit floats without rounding error then for every `k` we should get zero. But instead error increases with bigger values of k because of floating point error accumulation.
hth!
Problem
I've heard of "error" when using floating point variables. Now I'm trying to solve this puzzle and I think I'm getting some rounding/floating point error. So I'm finally going to figure out the basics of floating point error. What is a simple example of floating point/rounding error (preferably in C++) ? Edit: For example say I have an event that has probability p of succeeding. I do this event 10 times (p does not change and all trials are independent). What is the probability of exactly 2 successful trials? I have this coded as: ``` double p_2x_success = pow(1-p, (double)8) * pow(p, (double)2) * (double)choose(8, 2); ``` Is this an opportunity for floating point error?