📅  最后修改于: 2020-09-25 07:29:14             🧑  作者: Mango
该函数在
double copysign(double x, double y);
float copysign(float x, float y);
long double copysign(long double x, long double y);
Promoted copysign(Type1 x, Type2 y); // Additional overloads for arithmetic types
从C++ 11开始,如果传递给copysign()的任何参数为long double
,则返回的Promoted
类型为long double
。如果不是,则返回类型Promoted
为double
。
copysign() 函数返回值为x且值为y的值。
#include
#include
using namespace std;
int main()
{
double x = 34.15, y = -13.0, result;
result = copysign(x, y);
cout << "copysign(" << x << "," << y << ") = " << result << endl;
return 0;
}
运行该程序时,输出为:
copysign(34.15,-13) = -34.15
#include
#include
using namespace std;
int main()
{
double x = 34.15, result;
int y = -54;
result = copysign(x, y);
cout << "copysign(" << x << "," << y << ") = " << result << endl;
return 0;
}
运行该程序时,输出为:
copysign(34.15,-54) = -34.15