## WeBWorK Problems

### Problems with absolute tolerance ### Problems with absolute tolerance

Number of replies: 3
The following problem should, according to (), set the absolute tolerance to require accuracy to 5 decimal places, but it doesn't seem to. (50.045 is the correct answer, but 52 is marked correct).

########################################################################

DOCUMENT();

"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1; Context("Numeric");$a = Compute("42.055");
$b = Compute("7.999");$ans = $a +$b;
Context("LimitedNumeric");

BEGIN_TEXT
$a +$b = \{ans_rule(35)\}
END_TEXT

ANS(Compute("$ans")->with(tolType=>'absolute', tolerance=>1*E-5)->cmp); ENDDOCUMENT(); I can fix this by changing the answer checker line to ANS(Compute("$ans")->with(tolType=>'absolute', tolerance=>.000001)->cmp);

What am I missing? Thanks for your help! ### Re: Problems with absolute tolerance

by Davide Cervone -
I suspect the problem is the * in 1*E-5, which is not correct. You want just 1E-5. Tests seem to indicate that E-5 is being interpreted as 2.71828... (as though E were e and the -5 has no effect; it looks like E is defined as a subroutine (in PGbasicmacros.pl), which is passed -5 as an argument, which is being ignored as the procedure returns exp(1)). Then multiplying by 1 in 1*E-5 is just 2.71828... again. So you have set the tolerance to 2.71828... rather than .00001.

In any case, you want 1E-5 instead.

Davide ### Re: Problems with absolute tolerance

Davide -

Thanks for your help; this was the clue that I needed to figure it out. For the record, the syntax that works is:

ANS(Compute("$ans")->with(tolType=>'absolute', tolerance=>'1e-5')->cmp); in particular, ANS(Compute("$ans")->with(tolType=>'absolute', tolerance=>'1 E-5')->cmp);

does not seem to work.

I found the command

TEXT( pretty_print(Context()->{flags}));

very helpful in sorting this out.

I'll update the Wiki to correct the line that started all of this.

Thanks again, ANS(Compute($ans)->with(tolType=>'absolute', tolerance=>1E-5)->cmp);  should do the trick. Also, you don't need the quotes around $ans as they are essentially redundant (there is only a difference if \$ans is undefined).