Skip to content

Commit 7d844b4

Browse files
committed
Fix the DiffCalc/AnswerWithUnits.pg sample problem.
The problem uses the "Units" context, but never activates that context and selects the units to use. So the problem fails to render.
1 parent 5c1759a commit 7d844b4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/Parser/Legacy/NumberWithUnits.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ sub compare {
445445
my ($self, $other, $flag) = @_;
446446
$other = $self->promote($other);
447447

448+
warn $other->{units_ref}{factor} / $self->{units_ref}{factor};
448449
my $adjusted = $other->value * uc($other->{units_ref}{factor} / $self->{units_ref}{factor});
449450
my $ret = $self->value->compare($adjusted, $flag);
450451
$ret = ($self->{units} cmp $other->{units}) * ($flag ? -1 : 1)

tutorial/sample-problems/DiffCalc/AnswerWithUnits.pg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ DOCUMENT();
2525
loadMacros('PGstandard.pl', 'PGML.pl', 'contextUnits.pl', 'PGcourse.pl');
2626

2727
#:% section = setup
28-
#: First, set the variable for the functions in the problem to be t,
29-
#: and assign the units "seconds" to it.
28+
#: First select the "Units" context, allow units for "length" and "time" in the
29+
#: context, and set the variable for functions in the context to be `t`.
30+
#:
31+
#: Then, assign the units "seconds" to the variable `t`.
3032
#:
3133
#: Use the differentiation operator `->D('t')` to compute the derivated, and the
3234
#: evaluation method `->eval()` to evaluate it as a function. All of these will
3335
#: now have the expect units.
34-
Context()->variables->are(t => 'Real');
36+
Context('Units')->withUnitsFor('length', 'time')->variables->are(t => 'Real');
3537
Context()->assignUnits(t => 's');
3638

3739
$v0 = random(16, 96, 16);

0 commit comments

Comments
 (0)