WeBWorK Main Forum

Conditional Release Phrasing

Conditional Release Phrasing

by Ryan Maccombs -
Number of replies: 3
The phrasing on the main page goes

"you must score at least 40% on set ***."

but when you have a set with 5 problems and score 2 correct (40%) it still doesn't open. Actually, it appears to be when you score greater than 40% it opens. can someone direct me to the file that controls conditional releases is typically stored so I can fix the code, or alternatively the wording.
In reply to Ryan Maccombs

Re: Conditional Release Phrasing

by Danny Glin -
I was able to reproduce the behaviour you describe, but the problem isn't the condition being checked. It's a little more subtle than that.

For example, if I change the release condition on the same set to 50%, WeBWorK lets me access the subsequent set when I get exactly 50% on the related set (one of the problems in my five-problem set has two parts, which allows me to get exactly 50% on the set).

The code which checks the conditions is the function 'is_restricted' in /opt/webworkwebwork2/lib/WeBWorK/Utils.pm. In particular, the check is line 1146:
  if($r_score < $restriction) {
where $r_score is the score on the earlier set, and $restriction is the cutoff score. This returns true if the set is restricted, which is the desired behaviour based on the way the function is written.

The problem appears to be an issue of floating point arithmetic when WeBWorK calculates the total score for a set. In my test, the student's score is being calculated as 0.400000000000000022204460492503..., while the required score is being calculated as 0.400000005960464477539062500000... Thus in perl, the student has not achieved the required score to proceed to the next set.

This stems from the fact that all of the numbers are stored in binary, and the binary representation of 0.4 is a repeating decimal, meaning that calculations will introduce rounding error, so numbers that should be equal aren't necessarily.

I'm not sure what the right fix is here. Perhaps the easiest thing to do would be to round the two scores (student score and required score) to some number of decimal places before comparing?
In reply to Danny Glin

Re: Conditional Release Phrasing

by Ryan Maccombs -
Wow thanks for digging into this for me. I probably will just do something much more primitive and alter it to be

if($r_score < $restriction + .001) {

Thanks again!
--Ryan