Wrong calculated answers when using large numbers

Wrong calculated answers when using large numbers

by Peter Halverson -
Number of replies: 4

Moodle version 1.9 (I think)

Hi all,

We are running into a very frustrating bug in the quiz module, using Calculated questions.

Suppose I have this question:   What is 1E20 / {x}?

And I have this for my Correct answer formula:   1E20/{x}

Then moodle gives really crazy results in the "Edit the datasets" page.

Specifically, it claims that

1E20/{x} when {x} = 3.8 (randomly selected x value, is
1E20/3.8 = 2.63     (See attachment for screen shot)
This is really weird, and inconvenient.  Why would 10^20 / 3.8 by 2.63???
Am I doing something wrong?   Is there a work-around for this bug??
Thanks,
Peter Halverson
Attachment bug shot.jpg
Average of ratings: -
In reply to Peter Halverson

Re: Wrong calculated answers when using large numbers

by Pierre Pichet -

I will test this on Moodle UQAM and come back.

Pierre

The min and max values are correct, but not the Correct answer...

In reply to Peter Halverson

Re: Wrong calculated answers when using large numbers

by Pierre Pichet -

This is related to the limit of PHP to handle number with very large significant figures as your answer set with the first option ( 2 decimals) will be something like 26345678901234567890.12.

If, in the first editing page, you set for you answer parameter Format to significant figures instead of decimals and a value less than the 22 significant figures that is implied by your first settings , things will be OK

On UQAM installation, the limit is around 21.

 

Pierre

In reply to Pierre Pichet

Re: Wrong calculated answers when using large numbers

by Peter Halverson -

Hello Pierre,

Yes... you have identified a good work-around.  Thanks!

For anyone interested, the fix is illustrated in the attachment below.

It involves two things in the "Editing a calculated question" window.

(1)  Set "Correct answer shows [9]"

(2) Set "Format [significant figures"]

Peter Halverson

Attachment 9 sig fig.jpg
In reply to Peter Halverson

Re: Wrong calculated answers when using large numbers

by Pierre Pichet -

And in Moodle 2,0 you can change the answers settings directly in the dataset form.

 

Pierre

P.S. I will review the code to handle this more correctly in new engine code.