December 2005
Beginner to intermediate
618 pages
20h 19m
English
copysign
Makes the sign of a number match that of another number
#include <math.h> doublecopysign( doublex, doubley); floatcopysignf( floatx, floaty); long doublecopysignl( long doublex, long doubley);
The copysign() function
returns a value with the magnitude of its first argument and the
sign of its second argument.
/* 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.
Read now
Unlock full access