由于 java.lang.Math 中的三角函数非常慢:是否有一个库可以快速且良好地进行近似?在不损失太多精度的情况下,似乎可以将计算速度提高几倍。 (在我的机器上,乘法需要 1.5ns,java.lang.Math.sin 需要 46ns 到 116ns)。不幸的是,目前还没有使用硬件功能的方法。
更新:函数应该足够准确,例如 GPS 计算。这意味着您需要至少 7 个十进制数字的准确性,这排除了简单的查找表。它应该比基本 x86 系统上的 java.lang.Math.sin 快得多。否则就没有意义了。
对于 pi/4 以上的值,Java 会执行 some expensive computations除了硬件功能。这样做是有充分理由的,但有时您更关心速度而不是最后一点的准确性。
最佳答案
Computer Approximations通过哈特。表格 Chebyshev-economized一组不同精度的函数的近似公式。
编辑: 将我的副本下架,结果是 a different book听起来很相似。这是一个使用其表的 sin 函数。 (在 C 中测试,因为这对我来说更方便。)我不知道这是否会比 Java 内置更快,但至少可以保证它不那么准确。 :) 您可能需要先对参数进行范围缩小;见 John Cook's suggestions .本书还有arcsin和arctan。
#include <math.h>
#include <stdio.h>
// Return an approx to sin(pi/2 * x) where -1 <= x <= 1.
// In that range it has a max absolute error of 5e-9
// according to Hastings, Approximations For Digital Computers.
static double xsin (double x) {
double x2 = x * x;
return ((((.00015148419 * x2
- .00467376557) * x2
+ .07968967928) * x2
- .64596371106) * x2
+ 1.57079631847) * x;
}
int main () {
double pi = 4 * atan (1);
printf ("%.10f\n", xsin (0.77));
printf ("%.10f\n", sin (0.77 * (pi/2)));
return 0;
}
关于java - Java的快速超越/三角函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/523531/
如果我有一个基类和两个派生类,我想手工实现两个派生类之间的转换,有什么办法吗? (在 C# 中) abstract class AbsBase { private int A; priva
非常基本的场景: 我的 Nib 上有一个 NSTableView,有一个指向它的 socket 。我的应用程序委托(delegate)中有以下内容: - (void)applicationDidFin
我正在尝试使用 R 来估计具有手动规范的多项 logit 模型。我找到了一些可以让您估计 MNL 模型的软件包 here或 here . 我发现了一些关于“滚动”你自己的 MLE 函数的其他著作 he
我正在监视某些 FreeIPA 服务器,这些服务器通常 fork 300 覆盖我专门为同样继承“Template OS Linux”和“Template IPA Servers”的此类服务器创建的另一
我正在尝试分析文本,但我的 Mac 的 RAM 只有 8 GB,并且 RidgeRegressor 在一段时间后停止,并显示 Killed: 9。我认为这是因为它需要更多内存。 有没有办法禁用堆栈大小
我有一个名为 sourceTable 的数据表,其中包含 source_Id、title 和 programme_Id 列。第二个数据表是 credits,包含 credit_Id、programme
这或多或少是一个以框架为中心的版本 past Stack Overflow question ,这是关于 MVC 应用程序的大多数介绍性 Material 如何倾向于呈现模型、 View 和 Cont
从 Java 转向 Python,有人告诉我工厂不是 Pythonic。因此,我正在寻找 a Python 方法来执行如下操作。 (我过度简化了我的目标,这样我就不必描述我的整个程序,这非常复杂)。
当 UIButton 的框架位于其父框架之外时,UIButton(或任何其他控件)是否有可能接收触摸事件?因为当我尝试这个时,我的 UIButton 似乎无法接收任何事件。我该如何解决这个问题? 最佳
我以 VBto 为起点,并大量学习了 Delphi 6 User's Guide。我可以编译我的新组件,但我想不出办法让它显示,所以我可以完成调试。 50 年的编程经验也无济于事。这是我的组件的内容:
对于以下代码,我得到的平均计算时间为 50 毫秒。我该如何优化 filter(u -> myStrings.contains(u.getName()) 获得更快的计算时间? list size 300