@@ -23,13 +23,13 @@ =head1 DESCRIPTION
2323where the latter context, you or the student are not allowed to perform any operations on
2424any numbers.
2525
26- This is primarily for decimal numbers and keep track of signficant figures. With the context loaded,
26+ This is primarily for decimal numbers and keep track of significant figures. With the context loaded,
2727a call to C<Real > will parse the number or string to keep track of significant figures. For example,
2828
2929 $x = Real('10.45');
3030 $y = Real('37.1834');
3131
32- and these numbers will have 6 and 4 signficant figures respectively. To query the number of significant
32+ and these numbers will have 6 and 4 significant figures respectively. To query the number of significant
3333figures, use the C<sigfigs > method. For example, C<< $x->sigfigs >> will return 4.
3434
3535The standard arithmetic operations +, -, *, / are defined for these and the result will have the correct
@@ -41,7 +41,7 @@ =head1 DESCRIPTION
4141
4242 $x * $y;
4343
44- returns C<106.4 > (with only 4 signficant figures, since one of them only has four).
44+ returns C<106.4 > (with only 4 significant figures, since one of them only has four).
4545
4646Finally, we can also perform subtraction as in
4747
@@ -52,12 +52,12 @@ =head1 DESCRIPTION
5252
5353=head2 Significant Figure Rules
5454
55- A reminder about signficant figures is that all non-zero digits are significant. The rule about a zero's
55+ A reminder about significant figures is that all non-zero digits are significant. The rule about a zero's
5656significance depends on where it is in a number.
5757
5858=over
5959
60- =item * Zeros between any significant digits are signficant . The zeros in 12.0034 are significant. There are 6
60+ =item * Zeros between any significant digits are significant . The zeros in 12.0034 are significant. There are 6
6161significant figures in this number.
6262
6363=item * Zeros to the left of a non-zero digit are not significant. The zeros in 0.00123 are not signficant.
@@ -67,7 +67,7 @@ =head2 Significant Figure Rules
6767significant. There are 6 significant figures in this number.
6868
6969=item * Zeros to the left of the decimal point and to the right of a non zero digit are not significant. The
70- zeros in 12300 are not significant. There are 3 significant figures in this number. However, the presesence of
70+ zeros in 12300 are not significant. There are 3 significant figures in this number. However, the presence of
7171a significant zero changes the rule. The zeros in 12300.0 are all significant because the rightmost 0 is
7272significant and therefore the other zeros are significant.
7373
@@ -116,13 +116,26 @@ =head3 Setting the number of significant figures.
116116which has 6 significant figures. If C<< $x->sigfigs(4) >>, then the result is the number '12.35', where
117117rounding has been performed.
118118
119+ =head2 Flags
120+
121+ The flag C<partial_credit > on the context will award partial credit for an answer that is correct to
122+ within the given tolerance but the number of significant figures is not correct. In addition, a
123+ warning is shown to the student. The value of C<partial_credit > should be between 0 and 1.
124+
125+ For example,
126+
127+ Context('SignificantFigures')->flags->set(tolerance => 0.01, partial_credit => 0.6);
128+
129+ will set the tolerance to 0.01 (this is the same as tolerance for reals) and the amount of
130+ partial credit to give for the correct answer with wrong number of significant figures.
131+
119132=head2 SigFigNumber
120133
121134The function C<SigFigNumber > will also create a SigFigNumber with the second argument the number of
122135significant figures. For example,
123136
124137 $a = SigFigNumber(12.345);
125- $b = SigFigNumber(10000,3);
138+ $b = SigFigNumber(10000, 3);
126139
127140will create a number with 5 and 3 significant figures respectively.
128141
@@ -332,6 +345,29 @@ sub ROUND {
332345 return sprintf (" %.0E" , $x + $d ) - $d ;
333346}
334347
348+ # This method checks to see if the student answer is equal (in the Value::Real sense)
349+ # to the correct answer, but the incorrect number of significant figures.
350+ # If so, show a warning and given partial credit.
351+
352+ sub cmp_postprocess {
353+ my ($self , $ansHash ) = @_ ;
354+
355+ return unless $self -> getFlag(' partial_credit' ) && $ansHash -> score < 1;
356+
357+ my $student = $ansHash -> {student_value };
358+ my $correct = $ansHash -> {correct_value };
359+
360+ # Create Value::Real versions of the student and correct answer
361+
362+ my $student_real = Value::Real-> new($student -> string);
363+ my $correct_real = Value::Real-> new($correct -> string);
364+
365+ if ($student_real == $correct_real && $student -> sigfigs != $correct -> sigfigs) {
366+ $ansHash -> {ans_message } = " Incorrect number of significant figures" ;
367+ $ansHash -> score($self -> getFlag(' partial_credit' ));
368+ }
369+ }
370+
335371package context::SignificantFigures::BOP::parse ;
336372our @ISA = (" Parser::BOP" );
337373
0 commit comments