C++ c+中sinl和cosl函数的精度+;
我希望精度大约为C++ c+中sinl和cosl函数的精度+;,c++,precision,floating-accuracy,C++,Precision,Floating Accuracy,我希望精度大约为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="&l
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;
}
typedef结构p{
长双x;
长双y;
}点;
点旋转\点(长双cx,长双cy,长双角度,点p)//先旋转,再旋转角度,然后点旋转
{//cout不要使用该值
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)
不要说“不要作弊”来解决问题?!什么是angle=(angle/100)*pi*2;
应该做的?这不是度到弧度的转换,而是类似的。什么是pi
?也许你有pi=3.142
或其他crass值。使用数学库标题中定义的值。pi是#定义pi(22/7)事实上,它的角度到弧度转换(角度/100)*pi*(360/180)哈哈哈,我几乎认为它会如此糟糕。如果你想要精确的FFS,请使用一个好的pi值。虽然22/7在现实世界中是pi的粗略近似值,但在编程中它是一个糟糕的近似值:它的值是3。