numerical tolerance adjusting

numerical tolerance adjusting

by Jeff Forssell -
Number of replies: 3
I'm trying to find how the numerical questions work and an interesting aspect is the way numerical intervals are evaluated.

in numerical/questiontype.php there is this comment

// We need to add a tiny fraction depending on the set precision to make the
// comparison work correctly. Otherwise seemingly equal values can yield
// false. (fixes bug #3225)

I tried looking in the tracker but failed to find it. I would like to know examples of what comparisons (actual number examples) were failing.


Average of ratings: -
In reply to Jeff Forssell

Re: numerical tolerance adjusting

by Jeff Forssell -
Weird!

When i get a mailed copy of my post, the original text has been changed slightly:

// We need to add a tiny fraction depending on the set precision to make the
// comparison work correctly. Otherwise seemingly equal values can yield
// false. (f i x e s b u g # 3 2 2 5)

where (f i x e s b u g # 3 2 2 5) was changed to a link that takes me there.
(I wrote it spaced out now so it won't get changed again by some filter.)

Obviously I am still finding the tracker not fitting my kind of "intuition". thoughtful

I know I put 3225 into the quick search box and got nothing.

But if I do that now, I get to the issue! angry

I tried browsing issues, in questions and in quiz sorting by ID but didn't see it.
When I look now I'm wondering, is it only showing "unresolved" issues and that's why it didn't show?






In reply to Jeff Forssell

Re: numerical tolerance adjusting

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The problem is this: Working with limited precision (in base 10) add 1/3 + 1/3 + 1/3. You will end up with something like 0.99999.

Of course, computers work with base 2, but similar things happen. Therefore, when working floats on a computer, you should never test x == y. Instead you should do abs(x - y) < tol for a suitable tol.

When working with floats there is a quantity called epsion, which is the smallest number such that 1 + x > 1 in float arithmetic. Typically in PHP this is about 10^-15. Other things being equal, (in a non-mathematical sense) I have always felt that the square root of this, about 10^-7 or 10^-8 is a good value of tol.
In reply to Jeff Forssell

Re: numerical tolerance adjusting

by Pierre Pichet -

Hi Jeff,

This has been solved (the tiny interval) by using a value relative to the answer so that small values (i.e. 1e-23 in chemistry) are better handled.

This is to account for the limited precision of real numbers in the digital bit oriented world...

Pierre