本文介绍了如何Math.Pow(等)actualy作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我在Google上搜寻了很久,我发现几乎没有。我发现有关从的,但他们是不准确的,比如这个code
So I was googling for a long time and i found almost nothing. I found some info about possible implementation of Math.Pow from this url, but they are inaccurate, for example this code
public static double PowerA(double a, double b)
{
int tmp = (int)(BitConverter.DoubleToInt64Bits(a) >> 32);
int tmp2 = (int)(b * (tmp - 1072632447) + 1072632447);
return BitConverter.Int64BitsToDouble(((long)tmp2) << 32);
}
static void Main(string[] args)
{
double x = 12.53, y = 16.45;
Console.WriteLine(Math.Pow(x, y));
Console.WriteLine(PowerA(x, y));
}
提供输出:
1,15158266266297E+18
8,9966384455562E+17
所以,不准确的...
So inaccurate...
我在想,它就像一系列的总和,但我不知道某些事情。
I was thinking that it works like a sum of series but I don't know for certain.
推荐答案
战俘通常是由如下公式计算:
pow is usually evaluated by this formula:
x^y = exp2(y*log2(x))
- 在功能EXP2(X),LOG2(X)的FPU直接实施
- 如果你想实现大数
- 那么他们也可以通过基础运营商进行评估
- 与使用开方,权力precomputed表... 2 ^ 1/2,2 ^ 1/4,2 ^ 1/8,2 ^ 1/16,2 ^三十二分之一...
- 要加快这一进程
- functions exp2(x),log2(x) are directly implemented in FPU
- if you want to implement bignums
- then they can also be evaluated by basic operators
- with use of precomputed table of sqrt-powers ... 2^1/2, 2^1/4, 2^1/8, 2^1/16, 2^1/32 ...
- to speed up the process
这篇关于如何Math.Pow(等)actualy作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!