# How to emulate erf and/or the Normal Inverse function in Moodle?

I've just discovered "calculated questions" in Moodle and I'm trying to create a simple one where I would be asking the student to find the probability that an observation from a standard normal population be greater than variable $$\left\{z\right\}$$.

I then define the range of $$\left\{z\right\}$$ as $$[-3,3]$$ with $$2$$ decimal places.

Now since Moodle doesn't have erf implemented I have been trying to emulate it using Jack D'Aurizio's answer here, and otherwise Abramowitz and Stegun's first approximation given here, which results in $$P(z_i> z)\approx \frac{1-\sqrt{1-e^{-0.619495805z^2}}}2$$ for the former, for instance.

I am facing the problem that Moodle refuses to calculate this when $$z$$ is less than $$2$$ (I get the output NaN) and as for the values where it will output something, the outputs don't seem to depend much on $$z$$, I get only four different possible outputs which are $$0$$, $$0.005$$, $$0.035$$ and $$0.102$$.

Two examples copy-pasted from Moodle:

1-(1+sqrt(1-exp(-0.619495805*((40.14-11.7)/4.3)^2)))/2 = 0.035

1-(1+sqrt(1-exp(-0.619495805*((33.18-13)/4.1)^2)))/2 = 0.102

Where here $$\left\{z\right\}$$ was actually calculated via $$\left\{z\right\}=\frac{\left\{x\right\}-\left\{m\right\}}{\left\{s\right\}}$$

Does anyone know how to work around this and get actual proper values for the normal inverse function?

• I've never used Moodle, but according to moodle.org you cannot us ^ for powers; instead use pow({foo}, 2). – user1027 Nov 28 '19 at 21:00
• @user1527 Oh, good point. Now I wonder how it can calculate something in some cases then. Thanks, I'll try fixing that! – Arnaud Mortier Nov 28 '19 at 22:07
• @user1527 Well, you can post this as an answer and I will accept it. It fixed everything. I was really thrown off by the few numerical outputs, which got me thinking that it was a problem of too violent an approximation being done at some point by the software. – Arnaud Mortier Nov 28 '19 at 22:19

I've never used Moodle, but according to moodle.org you cannot use ^ for powers; instead use pow({foo}, 2).