You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Josh Milthorpe (JIRA)" <ji...@apache.org> on 2010/12/09 12:47:01 UTC
[jira] Created: (MATH-456) Erf.erf - handle infinities and large
values
Erf.erf - handle infinities and large values
--------------------------------------------
Key: MATH-456
URL: https://issues.apache.org/jira/browse/MATH-456
Project: Commons Math
Issue Type: Bug
Affects Versions: 3.0
Reporter: Josh Milthorpe
Priority: Minor
{{Erf.erf(double)}} crashes when presented with infinities or large values, as follows:
{noformat}
org.apache.commons.math.ConvergenceException: Continued fraction diverged to NaN for value ∞
at org.apache.commons.math.util.ContinuedFraction.evaluate(ContinuedFraction.java:186)
at org.apache.commons.math.special.Gamma.regularizedGammaQ(Gamma.java:266)
at org.apache.commons.math.special.Gamma.regularizedGammaP(Gamma.java:173)
at org.apache.commons.math.special.Erf.erf(Erf.java:56)
at TestInfErf.main(TestInfErf.java:9)
{noformat}
The following code demonstrates this crash:
{code}
import org.apache.commons.math.MathException;
import org.apache.commons.math.special.Erf;
public class TestInfErf {
public static void main(String[] args) {
try {
System.out.println("erf(Inf) = " + Erf.erf(Double.POSITIVE_INFINITY));
System.out.println("erf(-Inf) = " + Erf.erf(Double.NEGATIVE_INFINITY));
System.out.println("erf(Huge) = " + Erf.erf(1e300));
} catch (MathException e) {
e.printStackTrace();
}
}
}
{code}
At double precision, erf\(x\) = 1.0 for x > 6.0 and erf\(x\) = -1.0 for x < -6.0. Therefore Erf.java could be patched as follows:
{noformat}
Index: src/main/java/org/apache/commons/math/special/Erf.java
===================================================================
--- src/main/java/org/apache/commons/math/special/Erf.java (revision 1043888)
+++ src/main/java/org/apache/commons/math/special/Erf.java (working copy)
@@ -48,6 +48,12 @@
* @throws MathException if the algorithm fails to converge.
*/
public static double erf(double x) throws MathException {
+ // at double precision, erf(x) = (+/-)1.0 for |x| > 6.0
+ if (x > 6.0) {
+ return 1.0;
+ } else if (x <-6.0) {
+ return -1.0;
+ }
double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
if (x < 0) {
ret = -ret;
{noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (MATH-456) Erf.erf - handle infinities and large
values
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz resolved MATH-456.
------------------------------
Resolution: Fixed
Fixed in r1054184
> Erf.erf - handle infinities and large values
> --------------------------------------------
>
> Key: MATH-456
> URL: https://issues.apache.org/jira/browse/MATH-456
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 2.2
> Reporter: Josh Milthorpe
> Priority: Minor
> Fix For: 2.2
>
>
> {{Erf.erf(double)}} crashes when presented with infinities or large values, as follows:
> {noformat}
> org.apache.commons.math.ConvergenceException: Continued fraction diverged to NaN for value ∞
> at org.apache.commons.math.util.ContinuedFraction.evaluate(ContinuedFraction.java:186)
> at org.apache.commons.math.special.Gamma.regularizedGammaQ(Gamma.java:266)
> at org.apache.commons.math.special.Gamma.regularizedGammaP(Gamma.java:173)
> at org.apache.commons.math.special.Erf.erf(Erf.java:56)
> at TestInfErf.main(TestInfErf.java:9)
> {noformat}
> The following code demonstrates this crash:
> {code}
> import org.apache.commons.math.MathException;
> import org.apache.commons.math.special.Erf;
> public class TestInfErf {
> public static void main(String[] args) {
> try {
> System.out.println("erf(Inf) = " + Erf.erf(Double.POSITIVE_INFINITY));
> System.out.println("erf(-Inf) = " + Erf.erf(Double.NEGATIVE_INFINITY));
> System.out.println("erf(Huge) = " + Erf.erf(1e300));
> } catch (MathException e) {
> e.printStackTrace();
> }
> }
> }
> {code}
> At double precision, erf\(x\) = 1.0 for x > 6.0 and erf\(x\) = -1.0 for x < -6.0. Therefore Erf.java could be patched as follows:
> {noformat}
> Index: src/main/java/org/apache/commons/math/special/Erf.java
> ===================================================================
> --- src/main/java/org/apache/commons/math/special/Erf.java (revision 1043888)
> +++ src/main/java/org/apache/commons/math/special/Erf.java (working copy)
> @@ -48,6 +48,12 @@
> * @throws MathException if the algorithm fails to converge.
> */
> public static double erf(double x) throws MathException {
> + // at double precision, erf(x) = (+/-)1.0 for |x| > 6.0
> + if (x > 6.0) {
> + return 1.0;
> + } else if (x <-6.0) {
> + return -1.0;
> + }
> double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
> if (x < 0) {
> ret = -ret;
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] [Closed] (MATH-456) Erf.erf - handle infinities and large
values
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Luc Maisonobe closed MATH-456.
------------------------------
Closing issue as it was included in version 2.2, which has been released
> Erf.erf - handle infinities and large values
> --------------------------------------------
>
> Key: MATH-456
> URL: https://issues.apache.org/jira/browse/MATH-456
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 2.2
> Reporter: Josh Milthorpe
> Priority: Minor
> Fix For: 2.2
>
>
> {{Erf.erf(double)}} crashes when presented with infinities or large values, as follows:
> {noformat}
> org.apache.commons.math.ConvergenceException: Continued fraction diverged to NaN for value ∞
> at org.apache.commons.math.util.ContinuedFraction.evaluate(ContinuedFraction.java:186)
> at org.apache.commons.math.special.Gamma.regularizedGammaQ(Gamma.java:266)
> at org.apache.commons.math.special.Gamma.regularizedGammaP(Gamma.java:173)
> at org.apache.commons.math.special.Erf.erf(Erf.java:56)
> at TestInfErf.main(TestInfErf.java:9)
> {noformat}
> The following code demonstrates this crash:
> {code}
> import org.apache.commons.math.MathException;
> import org.apache.commons.math.special.Erf;
> public class TestInfErf {
> public static void main(String[] args) {
> try {
> System.out.println("erf(Inf) = " + Erf.erf(Double.POSITIVE_INFINITY));
> System.out.println("erf(-Inf) = " + Erf.erf(Double.NEGATIVE_INFINITY));
> System.out.println("erf(Huge) = " + Erf.erf(1e300));
> } catch (MathException e) {
> e.printStackTrace();
> }
> }
> }
> {code}
> At double precision, erf\(x\) = 1.0 for x > 6.0 and erf\(x\) = -1.0 for x < -6.0. Therefore Erf.java could be patched as follows:
> {noformat}
> Index: src/main/java/org/apache/commons/math/special/Erf.java
> ===================================================================
> --- src/main/java/org/apache/commons/math/special/Erf.java (revision 1043888)
> +++ src/main/java/org/apache/commons/math/special/Erf.java (working copy)
> @@ -48,6 +48,12 @@
> * @throws MathException if the algorithm fails to converge.
> */
> public static double erf(double x) throws MathException {
> + // at double precision, erf(x) = (+/-)1.0 for |x| > 6.0
> + if (x > 6.0) {
> + return 1.0;
> + } else if (x <-6.0) {
> + return -1.0;
> + }
> double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
> if (x < 0) {
> ret = -ret;
> {noformat}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Updated: (MATH-456) Erf.erf - handle infinities and large
values
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz updated MATH-456:
-----------------------------
Fix Version/s: 2.2
> Erf.erf - handle infinities and large values
> --------------------------------------------
>
> Key: MATH-456
> URL: https://issues.apache.org/jira/browse/MATH-456
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 2.2
> Reporter: Josh Milthorpe
> Priority: Minor
> Fix For: 2.2
>
>
> {{Erf.erf(double)}} crashes when presented with infinities or large values, as follows:
> {noformat}
> org.apache.commons.math.ConvergenceException: Continued fraction diverged to NaN for value ∞
> at org.apache.commons.math.util.ContinuedFraction.evaluate(ContinuedFraction.java:186)
> at org.apache.commons.math.special.Gamma.regularizedGammaQ(Gamma.java:266)
> at org.apache.commons.math.special.Gamma.regularizedGammaP(Gamma.java:173)
> at org.apache.commons.math.special.Erf.erf(Erf.java:56)
> at TestInfErf.main(TestInfErf.java:9)
> {noformat}
> The following code demonstrates this crash:
> {code}
> import org.apache.commons.math.MathException;
> import org.apache.commons.math.special.Erf;
> public class TestInfErf {
> public static void main(String[] args) {
> try {
> System.out.println("erf(Inf) = " + Erf.erf(Double.POSITIVE_INFINITY));
> System.out.println("erf(-Inf) = " + Erf.erf(Double.NEGATIVE_INFINITY));
> System.out.println("erf(Huge) = " + Erf.erf(1e300));
> } catch (MathException e) {
> e.printStackTrace();
> }
> }
> }
> {code}
> At double precision, erf\(x\) = 1.0 for x > 6.0 and erf\(x\) = -1.0 for x < -6.0. Therefore Erf.java could be patched as follows:
> {noformat}
> Index: src/main/java/org/apache/commons/math/special/Erf.java
> ===================================================================
> --- src/main/java/org/apache/commons/math/special/Erf.java (revision 1043888)
> +++ src/main/java/org/apache/commons/math/special/Erf.java (working copy)
> @@ -48,6 +48,12 @@
> * @throws MathException if the algorithm fails to converge.
> */
> public static double erf(double x) throws MathException {
> + // at double precision, erf(x) = (+/-)1.0 for |x| > 6.0
> + if (x > 6.0) {
> + return 1.0;
> + } else if (x <-6.0) {
> + return -1.0;
> + }
> double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
> if (x < 0) {
> ret = -ret;
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (MATH-456) Erf.erf - handle infinities and large
values
Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Phil Steitz updated MATH-456:
-----------------------------
Affects Version/s: (was: 3.0)
2.2
> Erf.erf - handle infinities and large values
> --------------------------------------------
>
> Key: MATH-456
> URL: https://issues.apache.org/jira/browse/MATH-456
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 2.2
> Reporter: Josh Milthorpe
> Priority: Minor
>
> {{Erf.erf(double)}} crashes when presented with infinities or large values, as follows:
> {noformat}
> org.apache.commons.math.ConvergenceException: Continued fraction diverged to NaN for value ∞
> at org.apache.commons.math.util.ContinuedFraction.evaluate(ContinuedFraction.java:186)
> at org.apache.commons.math.special.Gamma.regularizedGammaQ(Gamma.java:266)
> at org.apache.commons.math.special.Gamma.regularizedGammaP(Gamma.java:173)
> at org.apache.commons.math.special.Erf.erf(Erf.java:56)
> at TestInfErf.main(TestInfErf.java:9)
> {noformat}
> The following code demonstrates this crash:
> {code}
> import org.apache.commons.math.MathException;
> import org.apache.commons.math.special.Erf;
> public class TestInfErf {
> public static void main(String[] args) {
> try {
> System.out.println("erf(Inf) = " + Erf.erf(Double.POSITIVE_INFINITY));
> System.out.println("erf(-Inf) = " + Erf.erf(Double.NEGATIVE_INFINITY));
> System.out.println("erf(Huge) = " + Erf.erf(1e300));
> } catch (MathException e) {
> e.printStackTrace();
> }
> }
> }
> {code}
> At double precision, erf\(x\) = 1.0 for x > 6.0 and erf\(x\) = -1.0 for x < -6.0. Therefore Erf.java could be patched as follows:
> {noformat}
> Index: src/main/java/org/apache/commons/math/special/Erf.java
> ===================================================================
> --- src/main/java/org/apache/commons/math/special/Erf.java (revision 1043888)
> +++ src/main/java/org/apache/commons/math/special/Erf.java (working copy)
> @@ -48,6 +48,12 @@
> * @throws MathException if the algorithm fails to converge.
> */
> public static double erf(double x) throws MathException {
> + // at double precision, erf(x) = (+/-)1.0 for |x| > 6.0
> + if (x > 6.0) {
> + return 1.0;
> + } else if (x <-6.0) {
> + return -1.0;
> + }
> double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
> if (x < 0) {
> ret = -ret;
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.