Sinl 和 Cosl 函数在 C++ 中的准确性
accuracy of sinl and cosl function in c++
我想要大约 0.000001
的准确度。
typedef struct p {
long double x;
long double y;
}point;
point rotate_point(long double cx,long double cy,long double angle,point p) //pivot then angle then point to rotate
{ // cout<<"ncx="<<cx<<"cy="<<cy<<"x="<<p.x<<"y="<<p.y;
angle=(angle/100)*pi*2;
// translate point back to origin:
p.x -= cx;
p.y -= cy;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(20);
// rotate point
long double xnew = p.x * cosl(-angle) - p.y * sinl(-angle);
long double ynew = p.x * sinl(-angle) + p.y * cosl(-angle);
// translate point back:
p.x = xnew + cx;
p.y = ynew + cy;
cout<<"x="<<p.x<<"y="<<p.y;
return p;
}
这是我正在使用的代码段,我正在使用函数rotate_point
围绕给定枢轴旋转一个点,这里cx
,cy
是枢轴,point
是顺时针方向旋转的点,angle
是以度为单位传递的角度(我不能以弧度假设的那样传递它)。我的问题是当我调用带有值的函数时rotate_point(50,50,25, p)
其中p.x=50 p.y=100
则预期输出为 x=100 y=50
。
我正在x=99.99999000666841262458 y=49.96838777042233631365
,x
还可以,但y
不在所需的精度范围内。
不要使用值
pi = 22 / 7
如果你想要准确性。请使用
M_PI
在 math.h
中定义。在 MSVC 中,您还需要
#define _USE_MATH_DEFINES
以使以下值可用。
#define M_E 2.71828182845904523536 // e
#define M_LOG2E 1.44269504088896340736 // log2(e)
#define M_LOG10E 0.434294481903251827651 // log10(e)
#define M_LN2 0.693147180559945309417 // ln(2)
#define M_LN10 2.30258509299404568402 // ln(10)
#define M_PI 3.14159265358979323846 // pi
#define M_PI_2 1.57079632679489661923 // pi/2
#define M_PI_4 0.785398163397448309616 // pi/4
#define M_1_PI 0.318309886183790671538 // 1/pi
#define M_2_PI 0.636619772367581343076 // 2/pi
#define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi)
#define M_SQRT2 1.41421356237309504880 // sqrt(2)
#define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2)
相关文章:
- 如何在MNIST上提高网络运行的准确性
- 如何提高浮点二阶导数计算的准确性
- 定义三维空间中变换估计的准确性
- C++ 而循环计时器的准确性差异很大
- MNIST:准确性低于我在互联网上看到的结果
- 由于C++中双精度类型的准确性而导致的错误
- 如何提高Python的睡眠/暂停时间准确性
- ERF在Visual Studio MSVC中的准确性是多少
- 处理融合乘加浮点不准确性的通用方法
- Sinl 和 Cosl 函数在 C++ 中的准确性
- QML 计时器 - 如何提高准确性
- 使用频率分析提高替换密码的准确性
- lexical_cast斯特托夫斯特托尔德失去了准确性
- MLP:迭代次数与准确性之间的关系
- 如何提高OpenCV模板跟踪的准确性?要使用的参数
- 如何确定二进制数的小数部分的平移准确性
- 提高准确性的最佳图像匹配算法
- 双倍和准确性
- D3D11/C++ 像素着色器中 UV 插值的不准确性.如何避免
- 规范化介于 (0,1) 之间的C++变量以获得算术准确性