Math::Erf::Approx - pure Perl approximate implementation of the error function
This is a pure Perl implementation of the error function (a.k.a. the Gauss error function). It gives an approximation with a maximum absolute difference of 0.0005 from the real value.
This module can export two functions. Neither is exported by default. This module uses Sub::Exporter, so the functions can be renamed:
use Math::Erf::Approx -all => { -prefix => 'math_' };
erf($x)
Calculates the result of the error function for value $x.
erfc($x, \&erf)
Given a value $x and a code reference to an implementation of erf(), calculates the complement.
If the code reference is ommitted (which I'd expect would be the most usual case), then the default is the erf
function provided by this module.
It is possible to run a small test suite on this module using:
use Math::Erf::Approx; Math::Erf::Approx->run_tests;
Benchmarking against Games::Go::Erf (on a fairly underpowered netbook)...
Benchmark: timing 100000 iterations of GGE, MEA... GGE: 6 wallclock secs ( 6.34 usr + 0.01 sys = 6.35 CPU) @ 15748.03/s (n=100000) MEA: 3 wallclock secs ( 2.71 usr + 0.00 sys = 2.71 CPU) @ 36900.37/s (n=100000)
There are considerations other than raw speed though...
$[
to 1, which has been deprecated since Perl 5.12.http://en.wikipedia.org/wiki/Error_function.
Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables, ed Milton Abramowitz and Irene Stegun. ISBN 0-486-61272-4.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.