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?
For example, the irrational number pi equals approximately 3.14, rounded to two decimal places or three significant digits. As an example of rounding error, consider the speed of light in a vacuum. The official value is 299,792,458 meters per second.
A floating point number, is a positive or negative whole number with a decimal point. For example, 5.5, 0.25, and -103.342 are all floating point numbers, while 91, and 0 are not. Floating point numbers get their name from the way the decimal point can "float" to any position necessary.
Even if some numbers can be represented exactly by floating-point numbers and such numbers are called machine numbers, performing floating-point arithmetic may lead to roundoff error in the final result.
Floating-point error mitigation is the minimization of errors caused by the fact that real numbers cannot, in general, be accurately represented in a fixed space. By definition, floating-point error cannot be eliminated, and, at best, can only be managed.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With