copysign(), copysignf(), copysignl() — Copy the sign from one floating-point number to another

Standards

Standards / Extensions C or C++ Dependencies

Language Environment
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both OS/390® V2R6

Format

#define _AIX_COMPATIBILITY
#include <math.h>
#include <float.h>

double copysign(double x, double y);
C99:
#define _ISOC99_SOURCE
#include <math.h>
#include <float.h>

float copysignf(float x, float y);
long double copysignl(long double x, long  double y);
C++ TR1 C99:
#define _TR1_C99
#include <math.h>

float copysign(float x, float y); 
long double copysign(long double x, long double y);

General description

The copysign functions produce a value with the magnitude of x and the sign of y.

Restriction: The copysignf() function does not support the _FP_MODE_VARIABLE feature test macro.
Note: The following table shows the viable formats for these functions. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Function Hex IEEE
copysign X X
copysignf X X
copysignl X X

Returned value

The copysign functions return a value with the magnitude of x and the sign of y.

Related information