copysign


copysign

Makes the sign of a number match that of another number

 #include <math.h> double copysign ( double x , double y  ); float copysignf ( float x , float y  ); long double copysignl ( long double x , long double y  ); 

The copysign( ) function returns a value with the magnitude of its first argument and the sign of its second argument.

Example

 /* Test for signed zero values */ double x = copysign(0.0, -1.0); double y = copysign(0.0, +1.0);   printf( "x is %+.1f; y is %+.1f.\n", x, y);   printf( "%+.1f is %sequal to %+.1f.\n", x, ( x == y ) ? "" : "not " , y ) 

This code produces the following output:

 x is -0.0; y is +0.0. -0.0 is equal to +0.0. 

See Also

abs( ), fabs( ), fdim( ), fmax( ), fmin( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net