WeBWorK Problems

Negative mixed numbers are not handled correctly

Negative mixed numbers are not handled correctly

by Adam Weyhaupt -
Number of replies: 1
The following code should require that the student enter "-1 7/10", but this generates an error message "You can only use '-' with (non-negative) numbers"

Any thoughts?

Adam

----

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"contextFraction.pl",
);

$a1 = -17;
$a2 = 10;

Context("LimitedFraction");
$ansa = Compute("$a1/$a2");

Context()->texStrings;
BEGIN_TEXT

\( \frac{$a1}{$a2}= \) \{ans_rule(35) \} $BR$BR

END_TEXT
Context()->normalStrings;

ANS(Compute($ansa)->cmp);

ENDDOCUMENT();
In reply to Adam Weyhaupt

Re: Negative mixed numbers are not handled correctly

by Davide Cervone -
This is a bug in contetFraction.pl. I have fixerd it in the latest HEAD version, so check that out of the CVS repository to get the fix. Thanks for the bug report.

Incidentally, there are two improvements I'd recommend for your code snippet above. First, you don't need the Compute() in the ANS call, as $ansa is already a MathObject, so computing it again is a waste of time.

Second, you can use $ansa to generate the fraction in the text of the problem rather than having to write the LaTeX yourself, but you have to force it to use showMixedNumbers=>0 to get it to show as a pure fraction:

    \(\{$ansa->with(showProperFractions=>0)\} =\) \{ans_rule(35)\}
That way you don't have to have the same fraction twice and run the risk of getting the two instances out of synchronization when you change the definition of $ansa later. :-)

Davide