xref: /minix3/lib/libm/src/s_copysign.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
12fe8fb19SBen Gras /* @(#)s_copysign.c 5.1 93/09/24 */
22fe8fb19SBen Gras /*
32fe8fb19SBen Gras  * ====================================================
42fe8fb19SBen Gras  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
52fe8fb19SBen Gras  *
62fe8fb19SBen Gras  * Developed at SunPro, a Sun Microsystems, Inc. business.
72fe8fb19SBen Gras  * Permission to use, copy, modify, and distribute this
82fe8fb19SBen Gras  * software is freely granted, provided that this notice
92fe8fb19SBen Gras  * is preserved.
102fe8fb19SBen Gras  * ====================================================
112fe8fb19SBen Gras  */
122fe8fb19SBen Gras 
132fe8fb19SBen Gras #include <sys/cdefs.h>
142fe8fb19SBen Gras #if defined(LIBM_SCCS) && !defined(lint)
15*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: s_copysign.c,v 1.13 2015/05/14 19:26:12 joerg Exp $");
162fe8fb19SBen Gras #endif
172fe8fb19SBen Gras 
182fe8fb19SBen Gras /*
192fe8fb19SBen Gras  * copysign(double x, double y)
202fe8fb19SBen Gras  * copysign(x,y) returns a value with the magnitude of x and
212fe8fb19SBen Gras  * with the sign bit of y.
222fe8fb19SBen Gras  */
232fe8fb19SBen Gras 
242fe8fb19SBen Gras #include "math.h"
252fe8fb19SBen Gras #include "math_private.h"
262fe8fb19SBen Gras 
27*0a6a1f1dSLionel Sambuc #if !defined(__HAVE_LONG_DOUBLE) && !defined(__HAVE_IBM_LONGDOUBLE)
__strong_alias(_copysignl,copysign)28*0a6a1f1dSLionel Sambuc __strong_alias(_copysignl, copysign)
29*0a6a1f1dSLionel Sambuc __weak_alias(copysignl, copysign)
30*0a6a1f1dSLionel Sambuc #endif
31*0a6a1f1dSLionel Sambuc 
322fe8fb19SBen Gras double
332fe8fb19SBen Gras copysign(double x, double y)
342fe8fb19SBen Gras {
352fe8fb19SBen Gras 	u_int32_t hx,hy;
362fe8fb19SBen Gras 	GET_HIGH_WORD(hx,x);
372fe8fb19SBen Gras 	GET_HIGH_WORD(hy,y);
382fe8fb19SBen Gras 	SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
392fe8fb19SBen Gras         return x;
402fe8fb19SBen Gras }
41