在哪里可以找到标准数学函数的算法?

发布于 2024-08-20 01:59:08 字数 1539 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

埋葬我深情 2024-08-27 01:59:08

约翰·哈特 (John Hart) 计算机近似 1968 年,约翰·威利 (John Wiley) 和 John Hart儿子们。

理想情况下,计算应该与运行时执行的计算精确匹配。这可能很棘手。对于许多函数来说,没有级数可以在整个域上快速收敛,因此算法将各种方法组合在一起。

此外,还有各种浮点格式。大多数平台(我认为)现在都使用 IEEE 754。当我编写编译器时,ca。 1985 年,我不得不处理跨平台浮点格式。要把它做好是非常乏味的,因为你必须将数字一点一点地拼凑在一起,确保你得到的值是在目标机器上计算的精确值。我不知道你是否需要处理这个问题。

John Hart Computer Approximations 1968 by John Wiley & Sons.

The calculations ideally should match precisely what they would if done at runtime. That can be tricky. For many functions, no series converges quickly over the full domain, so algoritms paste together various methods.

Also, there are various floating point formats. Most platforms (I think) now use IEEE 754. When I wrote a compiler ca. 1985, I had to deal with cross-platform floating point formats. It was very tedious to get it right, because you have to piece the numbers together bit by bit, being sure that you get precisely the value that would be calculated on the target machine. I don't know if you have to deal with that.

就此别过 2024-08-27 01:59:08

让·米歇尔·穆勒 (Jean-Michel Muller) 的书和哈特 (Hart) 的书都是极好的推荐。

您真的有必要拥有版权吗?如果你能避免的话,那么进入编写数学库函数的行业通常是一个坏主意(我是作为一个专业人士这么说的)。我不知道 D 是否可以接受 BSD 许可的代码,但是有几个很好的开源实现可能会有所帮助。例如,您可能需要查看 Sun 的 FDLIBM。 Stephen Moshier 的 Cephes 也是一种可能,尽管它的许可情况有点奇怪,但我相信他过去一直愿意让人们根据其他许可证重新分发他的代码。

顺便说一句,除非您支持任意精度浮点(我认为 D 不支持),否则 libm 函数通常没有“渐近效率”的概念。

Jean-Michel Muller's book is an excellent recommendation, as is Hart.

Is it actually necessary for you to own the copyright? It's usually a bad idea to get into the business of writing math library functions if you can avoid it (and I say that as someone who does so professionally). I don't know whether or not D can take in BSD-licenced code, but there are several good open-source implementations that may prove helpful. You may want to look at Sun's FDLIBM, for example. Stephen Moshier's Cephes would also be a possibility, though its licensing situation is a little bit odd, but I believe that he's been willing to let people redistribute his code under other licenses in the past.

On a side-note, unless you're supporting arbitrary-precision floating-point (I don't think that D does), there isn't usually a notion of "asymptotic efficiency" for libm functions.

时间海 2024-08-27 01:59:08

正如您所料,其他语言中也会出现类似的问题:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StrictMath.html

帮助确保 Java 的可移植性
程序,一些的定义
这个包中的数字函数
要求他们生产相同的产品
结果已公布
算法。这些算法是
可从知名网络获取
库 netlib 作为包“Freely
可分发的数学库,”fdlibm。
这些算法被写成
C 编程语言,那么
可以理解为与所有人一起执行
浮点运算如下
Java浮点数的规则
算术。

我不知道 D 的数学函数运行时计算规则是什么,但您也许可以采用类似的技巧 - 将 fdlibm 的 C 源重新解释为 D。如果 D 调用特定于平台的 C 库,那么您有问题是在编译时可能无法预测运行时值。

我认为 fdlibm 的许可证非常宽松,您必须自己检查它是否适合在 D 中重新分发。我见过的一个版本需要保留版权声明,仅此而已。

As you'd expect, similar issues arise in other languages:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StrictMath.html

To help ensure portability of Java
programs, the definitions of some of
the numeric functions in this package
require that they produce the same
results as certain published
algorithms. These algorithms are
available from the well-known network
library netlib as the package "Freely
Distributable Math Library," fdlibm.
These algorithms, which are written in
the C programming language, are then
to be understood as executed with all
floating-point operations following
the rules of Java floating-point
arithmetic.

I don't know what D's rules are for runtime calculation of math functions, but you may be able to pull a similar trick - re-interpret the C source of fdlibm as D. If D calls platform-specific C libraries, then you have the problem that it may be impossible at compile time to predict the runtime value.

I think fdlibm's license is very permissive, you'd have to check for yourself whether it's suitable for redistribution in D. One version I've seen requires a copyright notice to be preserved, and that's it.

魄砕の薆 2024-08-27 01:59:08

我推荐的来源是 RW Hamming 的科学家和工程师的数值方法

这本书由多佛出版社出版,是一本廉价的平装书。

The source that I recommend is Numerical Methods for Scientists and Engineers by R. W. Hamming.

This book is published by Dover Press, and is an inexpensive paperback.

血之狂魔 2024-08-27 01:59:08

也许这对您有帮助(至少对于某些功能):
http://en.wikipedia.org/wiki/CORDIC

Maybe this helps you (at least for some of the functions):
http://en.wikipedia.org/wiki/CORDIC

梦一生花开无言 2024-08-27 01:59:08

多个来源,包括:

Abramowitz 和 Stegun,“数学函数手册”(可在线获取在线!)

Hart,“计算机近似”(已绝版,但很好)

还看到了其他几个关于三角函数的问题,包括“三角函数如何工作?" 和 "三角函数嵌入式系统”。

several sources, including:

Abramowitz and Stegun, "Handbook of Mathematical Functions" (available online!)

Hart, "Computer Approximations" (out of print but good)

also see the several other SO questions about trigonometry, including "How do Trigonometric Functions Work?" and "Trigonometric Functions on Embedded Systems".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文