1 | |
---|
2 | /* @(#)s_copysign.c 5.1 93/09/24 */ |
---|
3 | /* |
---|
4 | * ==================================================== |
---|
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
6 | * |
---|
7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
8 | * Permission to use, copy, modify, and distribute this |
---|
9 | * software is freely granted, provided that this notice |
---|
10 | * is preserved. |
---|
11 | * ==================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | FUNCTION |
---|
16 | <<copysign>>, <<copysignf>>---sign of <[y]>, magnitude of <[x]> |
---|
17 | |
---|
18 | INDEX |
---|
19 | copysign |
---|
20 | INDEX |
---|
21 | copysignf |
---|
22 | |
---|
23 | SYNOPSIS |
---|
24 | #include <math.h> |
---|
25 | double copysign (double <[x]>, double <[y]>); |
---|
26 | float copysignf (float <[x]>, float <[y]>); |
---|
27 | |
---|
28 | DESCRIPTION |
---|
29 | <<copysign>> constructs a number with the magnitude (absolute value) |
---|
30 | of its first argument, <[x]>, and the sign of its second argument, |
---|
31 | <[y]>. |
---|
32 | |
---|
33 | <<copysignf>> does the same thing; the two functions differ only in |
---|
34 | the type of their arguments and result. |
---|
35 | |
---|
36 | RETURNS |
---|
37 | <<copysign>> returns a <<double>> with the magnitude of |
---|
38 | <[x]> and the sign of <[y]>. |
---|
39 | <<copysignf>> returns a <<float>> with the magnitude of |
---|
40 | <[x]> and the sign of <[y]>. |
---|
41 | |
---|
42 | PORTABILITY |
---|
43 | <<copysign>> is not required by either ANSI C or the System V Interface |
---|
44 | Definition (Issue 2). |
---|
45 | |
---|
46 | */ |
---|
47 | |
---|
48 | /* |
---|
49 | * copysign(double x, double y) |
---|
50 | * copysign(x,y) returns a value with the magnitude of x and |
---|
51 | * with the sign bit of y. |
---|
52 | */ |
---|
53 | |
---|
54 | #include "fdlibm.h" |
---|
55 | |
---|
56 | #ifndef _DOUBLE_IS_32BITS |
---|
57 | |
---|
58 | #ifdef __STDC__ |
---|
59 | double copysign(double x, double y) |
---|
60 | #else |
---|
61 | double copysign(x,y) |
---|
62 | double x,y; |
---|
63 | #endif |
---|
64 | { |
---|
65 | __uint32_t hx,hy; |
---|
66 | GET_HIGH_WORD(hx,x); |
---|
67 | GET_HIGH_WORD(hy,y); |
---|
68 | SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000)); |
---|
69 | return x; |
---|
70 | } |
---|
71 | |
---|
72 | #endif /* _DOUBLE_IS_32BITS */ |
---|