C言語で主にマイコン用途で平方根の計算を行いたい。
もしくは、精度悪くてもいいので高速に行いたい人向けの情報です。
class Program
{
static void Main(string[] args)
{
sqrt(3, 20);
Console.ReadLine();
}
static float sqrt(float value, int count)
{
float value2 = 2.0f * value;
float result = 1.0f;
while(0 < count--)
{
//ニュートン法で平方根を求める
result -= (result * result - value) / value2;
Console.WriteLine($"==>{result}");
}
return result;
}
}
参照URL
http://math.stackexchange.com/questions/296102/fastest-square-root-algorithm
0 件のコメント:
コメントを投稿