summaryrefslogtreecommitdiff
path: root/lib/msun/src/s_copysign.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/msun/src/s_copysign.c')
-rw-r--r--lib/msun/src/s_copysign.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/msun/src/s_copysign.c b/lib/msun/src/s_copysign.c
new file mode 100644
index 000000000000..ec92acd078d4
--- /dev/null
+++ b/lib/msun/src/s_copysign.c
@@ -0,0 +1,42 @@
+/* @(#)s_copysign.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#ifndef lint
+static char rcsid[] = "$Id: s_copysign.c,v 1.1.1.1 1994/05/06 00:20:03 gclarkii Exp $";
+#endif
+
+/*
+ * copysign(double x, double y)
+ * copysign(x,y) returns a value with the magnitude of x and
+ * with the sign bit of y.
+ */
+
+#include "math.h"
+#include <machine/endian.h>
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define n0 1
+#else
+#define n0 0
+#endif
+
+#ifdef __STDC__
+ double copysign(double x, double y)
+#else
+ double copysign(x,y)
+ double x,y;
+#endif
+{
+ *(n0+(unsigned*)&x) =
+ (*(n0+(unsigned*)&x)&0x7fffffff)|(*(n0+(unsigned*)&y)&0x80000000);
+ return x;
+}