Commit 41b9617b authored by Rob Pike's avatar Rob Pike

fix ldexp, frexp, and make math package compile and test correctly

SVN=126423
parent 45288543
......@@ -28,8 +28,8 @@ func envc() int32;
func argv(int32) string;
func envv(int32) string;
func frexp(float64) (int32, float64); // break fp into exp,fract
func ldexp(int32, float64) float64; // make fp from exp,fract
func frexp(float64) (float64, int32); // break fp into exp,fract
func ldexp(float64, int32) float64; // make fp from exp,fract
func modf(float64) (float64, float64); // break fp into double.double
func isInf(float64, int32) bool; // test for infinity
func isNaN(float64) bool; // test for not-a-number
......
This diff is collapsed.
......@@ -358,7 +358,7 @@ func unpack(a double) (negative bool, exp int, num double) {
}
// find g,e such that a = g*10^e.
// guess 10-exponent using 2-exponent, then fine tune.
e2, g := sys.frexp(a);
g, e2 := sys.frexp(a);
e := int(e2 * .301029995663981);
g = a * pow10(-e);
for g < 1 {
......
......@@ -49,5 +49,5 @@ exp(arg double) double
xsq = fract*fract;
temp1 = ((p2*xsq+p1)*xsq+p0)*fract;
temp2 = ((xsq+q2)*xsq+q1)*xsq + q0;
return sys.ldexp(ent, sqrt2*(temp2+temp1)/(temp2-temp1));
return sys.ldexp(sqrt2*(temp2+temp1)/(temp2-temp1), ent);
}
......@@ -24,7 +24,7 @@ fmod(x, y double) double
y = -y;
}
yexp,yfr = sys.frexp(y);
yfr,yexp = sys.frexp(y);
sign = false;
if x < 0 {
r = -x;
......@@ -34,11 +34,11 @@ fmod(x, y double) double
}
for r >= y {
rexp,rfr = sys.frexp(r);
rfr,rexp = sys.frexp(r);
if rfr < yfr {
rexp = rexp - 1;
}
r = r - sys.ldexp(rexp-yexp, y);
r = r - sys.ldexp(y, rexp-yexp);
}
if sign {
r = -r;
......
......@@ -39,7 +39,7 @@ log(arg double) double
return sys.NaN();
}
exp,x = sys.frexp(arg);
x,exp = sys.frexp(arg);
for x < 0.5 {
x = x*2;
exp = exp-1;
......
......@@ -61,15 +61,14 @@ main()
ck(exp[i], math.exp(f));
ck(floor[i], math.floor(f));
ck(log[i], math.log(math.fabs(f)));
math.pow(10, f);
ck(pow[i], math.pow(10, f));
ck(sin[i], math.sin(f));
ck(sinh[i], math.sinh(f));
ck(sqrt[i], math.sqrt(math.fabs(f)));
ck(tan[i], math.tan(f));
ck(tanh[i], math.tanh(f));
// ck(math.fabs(tanh[i]*math.sqrt(2)),
// math.hypot(tanh[i], tanh[i]));
ck(math.fabs(tanh[i]*math.sqrt(2)),
math.hypot(tanh[i], tanh[i]));
}
}
......
......@@ -30,7 +30,7 @@ sqrt(arg double) double
return 0;
}
exp,x = sys.frexp(arg);
x,exp = sys.frexp(arg);
for x < 0.5 {
x = x*2;
exp = exp-1;
......
......@@ -402,15 +402,15 @@ modf(float64 d, float64 *ip)
* Keep the top 11+e bits; clear the rest.
*/
if(e <= 64-11)
x &= ~((uint64)1 << (64-11-e))-1;
x &= ~(((uint64)1 << (64LL-11LL-e))-1);
dd = *(float64*)&x;
*ip = dd;
return d - dd;
}
// func frexp(float64) (int32, float64); // break fp into exp,fract
// func frexp(float64) (float64, int32); // break fp into exp,fract
void
sys·frexp(float64 din, int32 iou, float64 dou)
sys·frexp(float64 din, float64 dou, int32 iou)
{
dou = frexp(din, &iou);
FLUSH(&dou);
......@@ -426,10 +426,10 @@ sys·ldexp(float64 din, int32 ein, float64 dou)
//func modf(float64) (float64, float64); // break fp into double+double
float64
sys·modf(float64 din, float64 dou1, float64 dou2)
sys·modf(float64 din, float64 integer, float64 fraction)
{
dou1 = modf(din, &dou2);
FLUSH(&dou2);
fraction = modf(din, &integer);
FLUSH(&fraction);
}
//func isinf(float64, int32 sign) bool; // test for infinity
......
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