… | |
… | |
18 | loadMacros("contextFraction.pl"); |
18 | loadMacros("contextFraction.pl"); |
19 | |
19 | |
20 | and then select the appropriate context -- one of the following three: |
20 | and then select the appropriate context -- one of the following three: |
21 | |
21 | |
22 | Context("Fraction"); |
22 | Context("Fraction"); |
23 | Context("Fraction-NoDecimal"); |
23 | Context("Fraction-NoDecimals"); |
24 | Context("LimitedFraction"); |
24 | Context("LimitedFraction"); |
25 | |
25 | |
26 | The first is the most general, and allows fractions to be intermixed |
26 | The first is the most general, and allows fractions to be intermixed |
27 | with real numbers, so 1/2 + .5 would be allowed. Also, 1/2.5 is |
27 | with real numbers, so 1/2 + .5 would be allowed. Also, 1/2.5 is |
28 | allowed, though it produces a real number, not a fraction, since this |
28 | allowed, though it produces a real number, not a fraction, since this |
… | |
… | |
86 | ANS($b->cmp); |
86 | ANS($b->cmp); |
87 | |
87 | |
88 | There are several options to the cmp() method that control how the |
88 | There are several options to the cmp() method that control how the |
89 | answer checker will work. The first is controls whether unreduced |
89 | answer checker will work. The first is controls whether unreduced |
90 | fractions are accepted as correct. Unreduced fractions are allowed in |
90 | fractions are accepted as correct. Unreduced fractions are allowed in |
91 | the Fraction and Fraction->NoDecimals contexts, but not in the |
91 | the Fraction and Fraction-NoDecimals contexts, but not in the |
92 | LimitedFraction context. You can control this using the |
92 | LimitedFraction context. You can control this using the |
93 | studentsMustReduceFractions option: |
93 | studentsMustReduceFractions option: |
94 | |
94 | |
95 | Context("Fraction"); |
95 | Context("Fraction"); |
96 | ANS(Compute("1/2")->cmp(studentsMustReduceFractions=>1)); |
96 | ANS(Compute("1/2")->cmp(studentsMustReduceFractions=>1)); |
… | |
… | |
137 | |
137 | |
138 | This determines whether division is allowed only between integers or |
138 | This determines whether division is allowed only between integers or |
139 | not. If you want to prevent division from accepting non-integers, |
139 | not. If you want to prevent division from accepting non-integers, |
140 | then set strictFractions=>1 (and also strictMinus=>1 and |
140 | then set strictFractions=>1 (and also strictMinus=>1 and |
141 | strictMultiplication=>1). These are all three 0 by default in the |
141 | strictMultiplication=>1). These are all three 0 by default in the |
142 | Fraction and Fraction->NoDecimals contexts, but 1 in LimitedFraction. |
142 | Fraction and Fraction-NoDecimals contexts, but 1 in LimitedFraction. |
143 | |
143 | |
144 | =item S<C<< allowProperFractions >>> |
144 | =item S<C<< allowProperFractions >>> |
145 | |
145 | |
146 | This determines whether a space between a whole number and a fraction |
146 | This determines whether a space between a whole number and a fraction |
147 | is interpretted as implicit multiplication (as it usually would be in |
147 | is interpretted as implicit multiplication (as it usually would be in |
148 | WeBWorK), or as addition, allowing "4 1/2" to mean "4 and 1/2". By |
148 | WeBWorK), or as addition, allowing "4 1/2" to mean "4 and 1/2". By |
149 | default, it acts as multiplication in the Fraction and |
149 | default, it acts as multiplication in the Fraction and |
150 | Fraction->NoDecimals contexts, and as addition in LimitedFraction. If |
150 | Fraction-NoDecimals contexts, and as addition in LimitedFraction. If |
151 | you set allowProperFractions=>1 you should also set reduceConstants=>0. |
151 | you set allowProperFractions=>1 you should also set reduceConstants=>0. |
152 | |
152 | |
153 | =item S<C<< requireProperFractions >>> |
153 | =item S<C<< requireProperFractions >>> |
154 | |
154 | |
155 | This determines whether fractions MUST be entered as proper fractions. |
155 | This determines whether fractions MUST be entered as proper fractions. |