copysign - C math.h

C examples for math.h:copysign

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Copy sign

Prototype

long double copysignl (long double x, long double y);
long double copysign (long double x, long double y);
     double copysign  (double x     , double y);
     double copysign (double x     , double y);
      float copysignf (float x      , float y);
      float copysign (float x      , float y);
     double copysign (Type1 x      , Type2 y);       

Parameters

Parameter Description
x Value with the magnitude of the resulting value.
y Value with the sign of the resulting value.

Return Value

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

Example

Demo Code

#include <stdio.h>
#include <math.h> /* copysign */

int main ()//from   w  ww.j  a  v  a 2s .  c om
{
  printf ("%f\n", copysign( 10.0,-1.0));
 
  printf ("%f\n", copysign(-10.0,-1.0));
 
  printf ("%f\n", copysign(-10.0, 1.0));

  return 0;
}

Related Tutorials