Annotation of src/lib/libm/src/s_copysign.c, Revision 1.3
1.1 jtc 1: /* @(#)s_copysign.c 5.1 93/09/24 */
2: /*
3: * ====================================================
4: * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5: *
6: * Developed at SunPro, a Sun Microsystems, Inc. business.
7: * Permission to use, copy, modify, and distribute this
8: * software is freely granted, provided that this notice
9: * is preserved.
10: * ====================================================
11: */
1.3 ! jtc 12:
! 13: #ifndef lint
! 14: static char rcsid[] = "$Id: $";
! 15: #endif
1.1 jtc 16:
17: /*
18: * copysign(double x, double y)
19: * copysign(x,y) returns a value with the magnitude of x and
20: * with the sign bit of y.
21: */
22:
1.2 jtc 23: #include <math.h>
1.1 jtc 24:
25: #ifdef __STDC__
26: static const double one = 1.0;
27: #else
28: static double one = 1.0;
29: #endif
30:
31: #ifdef __STDC__
32: double copysign(double x, double y)
33: #else
34: double copysign(x,y)
35: double x,y;
36: #endif
37: {
38: int n0;
39: n0 = ((*(int*)&one)>>29)^1; /* high word index */
40: *(n0+(unsigned*)&x) =
41: (*(n0+(unsigned*)&x)&0x7fffffff)|(*(n0+(unsigned*)&y)&0x80000000);
42: return x;
43: }
CVSweb <webmaster@jp.NetBSD.org>