![]() |
The copysign() function in C is part of the standard math library <math.h> and is used to create a floating-point number that combines the magnitude of one number with the sign of another. It copies the sign from one floating-point number and applies it to the magnitude of another floating-point number. In this article, we will learn about the copysign() function in C and Syntax of copysign() in Cdouble copysign(double x, double y); ParameterThe copysign() function in C takes the following parameters:
Return ValueThe copysign() function returns a value that has the same magnitude as x but the sign of y. Variants of copysign() in CApart from the standard copysign() function, there are two more variants of the copysign() function, based on the type of floating-point numbers: copysignf() for floatfloat copysignf(float x, float y); copysignl() for long doublelong double copysignl(long double x, long double y); Note: The operation performed by copysign is at the bit level, making it both efficient and reliable. Examples of copysign() Function in C LanguageExample 1: Program to demonstrate how to use the copysign() function
Output The value with magnitude 10.50 and sign -5.50 is: -10.50 Time Complexity: O(1) Example 2: Program to demonstrate how to use the variants of copysign()
Output The value with magnitude 10.50 and sign -5.50 is: -10.50 The value with magnitude 20.50 and sign -6.50 is: -20.50 The value with magnitude 30.50 and sign -7.50 is: -30.50 Time Complexity: O(1) Practical Applications of copysign() FunctionThe copysign() function is particularly useful in various scenarios, such as:
|
Reffered: https://www.geeksforgeeks.org
C Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 17 |