Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is copysignl in C?

Sheza Munir

The copysignl function returns the value formed by combining the magnitude of the first parameter and the sign of the second parameter.

The copysignl function is a variation of the copysign function. The l in the variation refers to long double datatype of the parameter and the return value.

the return value is a combination of the two parameters

Library

The copysignl function can be accessed via the math.h library.

Syntax

long double copysignl(long double x, long double y)

Parameters

The copysignl function takes two parameters of the long double datatype.

Return value

If no errors occur, the copysignl function returns a value of long double datatype. This value has the magnitude of the first parameter and the sign of the second parameter.

If the first parameter is NaN (not a number), then the return value is NaN with the sign of the second parameter.

If the second parameter is -0, a negative value is returned (if a signed zero is supported in arithmetic operations).

The copysignl function provides a way to manipulate the sign of NaN.

Code

The following code shows the return values associated to different kinds of parameters.

#include <stdio.h>
#include <math.h>
 
int main()
{
    printf("copysignl(10000,+4.0)      = %Lf\n", copysignl(10000,+4.0)); //%Lf is the string formatter for long double values
    printf("copysignl(200000,-8.0)     = %Lf\n", copysignl(200000,-8.0));
    printf("copysignl(INFINITY,-2.0)   = %Lf\n", copysignl(INFINITY,-2.0));
    printf("copysignl(NAN,-3.0)        = %Lf\n", copysignl(NAN,-3.0));
}

RELATED TAGS

c

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring