## WeBWorK Main Forum

### error parsing scientific notation

by Gabriela Sanchis -
Number of replies: 6

I wrote a problem where the correct answer is (1+$beta)**(-$r). The student's version has $beta=4 and$r=7, but when the student enter 5^(-7) it is marked incorrect. I suspect that it has something to do with how webwork is parsing scientific notation. Webwork says the correct answer is 1.28e-5 and that the entered answer is 1.28E-5. How can I fix this?

### Re: error parsing scientific notation

by Danny Glin -

Can you please post the full code that is causing this?

### Re: error parsing scientific notation

by Gabriela Sanchis -

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; ############################################################## # # Setup # # Context("Numeric"); #$k=random(0,2); #pick negative binomial, Binomial,, or Poisson

$k=0; if ($k==0) #negative binomial

{$r=random(1,7);$beta=list_random(1,3,4,.25);

#$beta=.25,$r=3;

$a=$beta/(1+$beta);$b=($r-1)*$a;

$c1=$a+$b;$c2=$a+$b/2;

$c3=(-$r)*(ln(1+$beta));$ans=exp(($c3));} if ($k==1) #Poisson

{$c1=random(.1,.9,.1); #this is lambda; it's also b$c2=$c1/2;$ans=exp(-$c1);} if ($k==2) #Binomial

{$q=list_random(.2,.5,.6,.8);$m=random(2,5);

$a=-$q/(1-$q);$b=-($m+1)*$a;

$c1=$a+$b;$c2=$a+$b/2;

$ans=(1-$q)**$m;}; ############################################################## # # Text # # Context()->texStrings; BEGIN_TEXT For a distribution in the $$(a,b,0)$$ class, you are given that $$p_1=c1 p_0$$ and $$p_2=c2 p_1$$.$BR

Determine $$p_0$$.

$BR answer=\{ans_rule\} END_TEXT Context()->normalStrings; ############################################################## # # Answers # # ANS(Compute($ans)->cmp);

# relative tolerance --3.1412 is incorrect but 3.1413 is correct

# default tolerance is .01 or one percent.

### Re: error parsing scientific notation

by Alex Jordan -

Hi Gabriela,

I think this code may not be exactly the same problem file where you first described the issue. This code only allows the exponent for the answer to be from 2,3,4,5, but you described a situation where the exponent was 7. To diagnose the issue, it might be important to have exactly the right problem file where this first happened. And if you can access it, exactly the right seed that was used for that student version may help.

Alex

### Re: error parsing scientific notation

by Gabriela Sanchis -

The seed that's causing me problems is 3810. k=0, so r is picked randomly from 1 to 7 (in this case it picks 7), and beta is picked randomly from the list 1, 3, 4, .25 (in this case it picks 4). I had coded the answer as (1+$beta)**(-$r), then changed it to exp(-$r*ln(1+$beta)), which should be equivalent. The answer should be 5^(-7), but it's marking it wrong.

### Re: error parsing scientific notation

by Danny Glin -
See https://github.com/openwebwork/pg/issues/655 for more detail.

If your answer is already a real number, you should use Real($ans) rather than Compute($ans), since Compute expects a string and not a number, i.e.

ANS(Real($ans)->cmp); If you wanted to display a specific form of the answer to the student, then you can pass a string to Compute. e.g. if you use$ans = Compute("(1+$beta)^-$r");

Then ANS(\$ans->cmp) will display the typeset formula (1+4)^{-7} when you click "Show correct answer".