计算机如何计算平方根? [英] How does the computer calculate Square roots?

查看:1295
本文介绍了计算机如何计算平方根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算机如何计算平方根?
我的意思是那里发生了什么!它如何处理它!
它使用一些数学方法,如牛顿的方法?
三角函数怎么办?几乎所有的数学函数。
在每种语言都有自己的方式的情况下,请让我们谈谈c ++。

How does the computer calculate Square roots ? I mean what is going on there! How does it process it!! Does it use some mathematical ways like Newton's method? What about Trigonometric Functions? And almost all those Mathematical Functions . In the case that every language has its own way, then please let's talk about c++.

推荐答案

嵌入式CPU(例如x86和较大的ARM内核)具有直接计算平方根的硬件指令。支持这些指令的硬件实现是不同的,但通常是教科书逐位算法的变体(尽管不总是在基本二;基本四或十六也可以使用)。这些通常是CPU上最慢的基本算术运算;

Most modern non-embedded CPUs (x86 and the larger ARM cores, for example) have hardware instructions to compute square roots directly. The hardware implementation backing these instructions varies, but typically is a variant on the schoolbook digit-by-digit algorithm (though not always in base two; base four or sixteen can also be used). These are typically among the slowest basic arithmetic operations on a CPU; timings like 16-64 cycles are not uncommon, and these instructions are often not pipelined.

在没有直接硬件平方根指令(Itanium,PPC和其他)的CPU上,典型的方法是生成初始估计(使用产生估计的指令,或利用查找表),然后使用迭代法(通常为牛顿或戈德施密特)来精化该估计。

On CPUs that lack direct hardware square root instructions (Itanium, PPC, others), the typical approach is to generate an initial estimate (either with an instruction that produces the estimate, or with a lookup table) and then refine that estimate using an iterative method (Newton or Goldschmidt usually). You might track down some of Peter Markstein or Roger Golliver's writings on the subject if you're interested.

更复杂的数学函数(如trig操作)通常通过减少将参数引入一些基本域,然后用多项式或有理函数逼近它。您可以查看在线获得更多详细信息的几个数学库中的任何一个的来源(fdlibm是一个很好的起点)。

More complex mathematical functions (like trig operations) are typically computed by reducing the argument into some fundamental domain and then approximating it with a polynomial or rational function. You can look at the sources of any of several math libraries that are available online for more detail (fdlibm is a good starting point).

x86指令集提供了一个数字支持exp,log和sin等数学函数的指令,但是这些指令不再使用,因为良好的软件库实现提供了更好的性能。

The x86 instruction set provides a number of instructions that support mathematical functions like exp, log, and sin, but these are not commonly used anymore, because good software library implementations give better performance.

这篇关于计算机如何计算平方根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆