"vscode:/vscode.git/clone" did not exist on "9b3a1c3c40ed8b61f1468e91dc5017548faaa3c1"
Commit 19f80abb authored by Luís Fonseca's avatar Luís Fonseca Committed by Arnim Läuger
Browse files

Fix float math.pow when number was negative and power was odd (#1492)

parent 3109497b
...@@ -59,6 +59,7 @@ double pow(double x, double y) ...@@ -59,6 +59,7 @@ double pow(double x, double y)
{ {
double frexp(), g, ldexp(), r, u1, u2, v, w, w1, w2, y1, y2, z; double frexp(), g, ldexp(), r, u1, u2, v, w, w1, w2, y1, y2, z;
int iw1, m, p; int iw1, m, p;
bool flipsignal = false;
if (y == 0.0) if (y == 0.0)
return (1.0); return (1.0);
...@@ -67,7 +68,7 @@ double pow(double x, double y) ...@@ -67,7 +68,7 @@ double pow(double x, double y)
if (x == 0.0) if (x == 0.0)
{ {
if (y > 0.0) if (y > 0.0)
return (x); return 0.0;
//cmemsg(FP_POWO, &y); //cmemsg(FP_POWO, &y);
//return(HUGE); //return(HUGE);
} }
...@@ -75,6 +76,11 @@ double pow(double x, double y) ...@@ -75,6 +76,11 @@ double pow(double x, double y)
{ {
//cmemsg(FP_POWN, &x); //cmemsg(FP_POWN, &x);
x = -x; x = -x;
if (y != (int) y) { // if y is fractional, then this woud result in a complex number
return NAN;
}
flipsignal = ((int) y) & 1;
} }
} }
g = frexp(x, &m); g = frexp(x, &m);
...@@ -125,7 +131,8 @@ double pow(double x, double y) ...@@ -125,7 +131,8 @@ double pow(double x, double y)
p = 16 * m - iw1; p = 16 * m - iw1;
z = ((((((q7 * w2 + q6) * w2 + q5) * w2 + q4) * w2 + q3) * w2 + q2) * w2 + q1) * w2; z = ((((((q7 * w2 + q6) * w2 + q5) * w2 + q4) * w2 + q3) * w2 + q2) * w2 + q1) * w2;
z = a1[p] + a1[p] * z; z = a1[p] + a1[p] * z;
return (ldexp(z, m)); double res = ldexp(z, m);
return flipsignal ? -res : res;
} }
#if 0 #if 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment