I think Bruce was going to say to use
ANS(Compute("0.5")->cmp( checker => sub { my ($correct,$student,$ans) = @_; my $x = $student->value; return $x > 1 && $x < 2; }));which is essentially what I was going to suggest as well.
There is an issue to consider, however, and that's the use of $student->value
rather than $student
itself. If one uses $student
, then the MathObject's fuzzy real comparisons will be used, so that values that are fuzzy-equal to 1 or 2 will be excluded (i.e., the check is really more like $x > 1+epsilon && $x < 2-epsilon
). The difference would be whether you expect students to enter a computed value (a numeric formula) or to type a decimal directly. If it is a formula that they will be computing, you might want to use the fuzzy check, so that something that computes 1.99999 (but should have been 2 had it not been for round-off errors) will not be counted as correct, as it would when the non-fuzzy check it performed.
I'm not sure which I think is the right approach. It really depends on the problem, how you expect students to approach it, and how likely you think answers near the endpoints will be.
Davide