l****c 发帖数: 782 | 1 Write a Square Root function for a computer without floating point
calculations?
无从下手啊。。。。。 |
w****x 发帖数: 2483 | 2 //Write a program to find the square root of a given numbe
//Binary search again.
double GetSquareRoot(double f, double exp)
{
assert((f > 0.0 || abs(f) < exp) && exp > 0.0);
double dbBeg = 0.0;
double dbEnd = f;
if (f < 1.0) dbEnd = 1.0;
int nCount = 100;
do
{
double dbMid = (dbBeg + dbEnd)/2.0;
double dbSqrDiff = dbMid*dbMid - f;
if (abs(dbSqrDiff) < exp)
break;
if (dbSqrDiff < 0.0)
dbBeg = dbMid;
else
dbEnd = dbMid;
} while (nCount-- >= 0);
return (dbBeg + dbEnd)/2.0;
} |
l****c 发帖数: 782 | 3 但是要求without floating point calculation怎么办呢大牛?
【在 w****x 的大作中提到】 : //Write a program to find the square root of a given numbe : //Binary search again. : double GetSquareRoot(double f, double exp) : { : assert((f > 0.0 || abs(f) < exp) && exp > 0.0); : double dbBeg = 0.0; : double dbEnd = f; : if (f < 1.0) dbEnd = 1.0; : int nCount = 100; : do
|
f*****e 发帖数: 2992 | 4 看看汇编和linux内核是怎么算sqrt的。隔壁programming版就有。
【在 l****c 的大作中提到】 : Write a Square Root function for a computer without floating point : calculations? : 无从下手啊。。。。。
|
w****x 发帖数: 2483 | 5
那只有问北二牛了
【在 l****c 的大作中提到】 : 但是要求without floating point calculation怎么办呢大牛?
|