WeBWorK Problems

issue in contextFraction.pl

issue in contextFraction.pl

by Carl Yao -
Number of replies: 2

I'm writing to report an issue in contextFraction.pl. The following code changed the value of 3/2 to 1/2.

Carl Yao


$a1 = Fraction(3,2);
$test = Compute("$a1");



In reply to Carl Yao

Re: issue in contextFraction.pl

by Alex Jordan -
Hi Carl,

That is expected behavior. You set the showMixedNumbers flag to 1, so "$a1" comes out as "1 1/2".

However you haven't changed any flags to make the parser interpret mixed numbers as mixed numbers. The Compute call sees "1 1/2" and multiplies 1 by 1/2, giving you 1/2.

If you want a space to count as addition, as with mixed numbers, instead of multiplication, then you need to set some other flag for that or use a different context than plain Fraction.

See the contextFraction.pl documentation here:

In reply to Carl Yao

Re: issue in contextFraction.pl

by Davide Cervone -
When you do "$a1", because you are showing mixed numbers, you get "1 1/2" as the string passed to Compute(). But the space is implicit multiplication, so you compute effectively "1*1/2", which is 1. If you want to process mixed numbers (not just show them), you need to include the allowMixedNumbers=>1 flag as well.

It is not clear to me why you are doing the Compute() at all, since $a1 is already a MathObject. There is no need to recompute it that I can think of.

OOPS! I see Alex already answered. Sorry for the noise.