copysign() function in C++
copysign(x, y) function returns the value with a magnitude of x and the sign of y.
Examples:
Input : copysign(6, -2) Output : -6 Input : copysign(-6, 2) Output : 6
Syntax:
copysign(x, y);
Parameters:
x : Value with the magnitude y : Value with the sign
Returns :
Returns the value with a magnitude of x and the sign of y. Return type follows type casting i.e., if If one element is float and second element int then it returns float.
Below is the implementation of the above:
// C++ program to return copysign value #include <bits/stdc++.h> using namespace std; int main () { cout << "Magnitude = 6 Sign = -2 " << endl; cout << "Copysign(6, -2) = " << copysign(6, -2) << endl; cout << endl; cout << "Magnitude = -6 Sign = 2 " << endl; cout << "Copysign(-6, 2) = " << copysign(-6, 2); return 0; } |
chevron_right
filter_none
Output:
Magnitude = 6 Sign = -2 Copysign(6, -2) = -6 Magnitude = -6 Sign = 2 Copysign(-6, 2) = 6
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- fma() function in C++
- exp() function C++
- log() function in C++
- div() function in C++
- wcstol() function in C/C++
- wcstod() function in C/C++
- fegetexceptflag() function in C/C++
- mbsinit() Function in C/C++
- bit_and function in C++
- wcrtomb() function in C/C++
- wmemchr() function in C/C++
- vswprintf() function in C/C++
- wmemcmp() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



