A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/cmath/copysign/ below:

function

<cmath> <ctgmath>

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

Copy sign

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

Header

<tgmath.h>

provides a type-generic macro version of this function.


Additional overloads

are provided in this header (

<cmath>

) for other combinations of

arithmetic types

(

Type1

and

Type2

): These overloads effectively cast its arguments to

double

before calculations, except if at least one of the arguments is of type

long double

(in which case both are casted to

long double

instead).



Parameters
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
1
2
3
4
5
6
7
8
9
10
11
12
/* copysign example */
#include <stdio.h>      /* printf */
#include <math.h>       /* copysign */

int main ()
{
  printf ("copysign ( 10.0,-1.0) = %f\n", copysign( 10.0,-1.0));
  printf ("copysign (-10.0,-1.0) = %f\n", copysign(-10.0,-1.0));
  printf ("copysign (-10.0, 1.0) = %f\n", copysign(-10.0, 1.0));

  return 0;
}

Output:
copysign ( 10.0,-1.0) = -10.0
copysign (-10.0,-1.0) = -10.0
copysign (-10.0, 1.0) = 10.0


See also
fabs
Compute absolute value (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4