Skip to content

Commit bf436b1

Browse files
committed
erf bugfix.
1 parent 5bfe693 commit bf436b1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/org/python/modules/math_erf.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public static double erf(double x) {
132132
}
133133
return erx + P/Q;
134134
}
135+
135136
if (x >= 6) { // inf > |x| >= 6
136137
if (sign) {
137138
return -1;
@@ -148,8 +149,10 @@ public static double erf(double x) {
148149
R = rb0 + s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(rb5+s*rb6)))));
149150
S = 1 + s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(sb5+s*(sb6+s*sb7))))));
150151
}
152+
151153
// pseudo-single (20-bit) precision x
152-
double z = (double)(Double.doubleToLongBits(x) & 0xffffffff00000000L);
154+
long t20 = Double.doubleToLongBits(x) & 0xffffffff00000000L;
155+
double z = Double.longBitsToDouble(t20);
153156
double r = Math.exp(-z*z-0.5625) * Math.exp((z-x)*(z+x)+R/S);
154157
if (sign) {
155158
return r/x - 1;
@@ -219,7 +222,8 @@ public static double erfc(double x) {
219222
S = 1 + s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(sb5+s*(sb6+s*sb7))))));
220223
}
221224
// pseudo-single (20-bit) precision x
222-
double z = (double)(Double.doubleToLongBits(x) & 0xffffffff00000000L);
225+
long t20 = Double.doubleToLongBits(x) & 0xffffffff00000000L;
226+
double z = Double.longBitsToDouble(t20);
223227
double r = Math.exp(-z*z-0.5625) * Math.exp((z-x)*(z+x)+R/S);
224228
if (sign) {
225229
return 2 - r/x;

0 commit comments

Comments
 (0)