| Rev | Line |   | 
|---|
| [1] | 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 |  * copysign(double x, double y) | 
|---|
 | 16 |  * copysign(x,y) returns a value with the magnitude of x and | 
|---|
 | 17 |  * with the sign bit of y. | 
|---|
 | 18 |  */ | 
|---|
 | 19 |  | 
|---|
 | 20 | #include <libm/fdlibm.h> | 
|---|
 | 21 |  | 
|---|
 | 22 | #ifdef __STDC__ | 
|---|
 | 23 | static const double one = 1.0; | 
|---|
 | 24 | #else | 
|---|
 | 25 | static double one = 1.0; | 
|---|
 | 26 | #endif | 
|---|
 | 27 |  | 
|---|
 | 28 | #ifdef __STDC__ | 
|---|
 | 29 |         double copysign(double x, double y) | 
|---|
 | 30 | #else | 
|---|
 | 31 |         double copysign(x,y) | 
|---|
 | 32 |         double x,y; | 
|---|
 | 33 | #endif | 
|---|
 | 34 | { | 
|---|
 | 35 |         int     n0; | 
|---|
 | 36 |         n0 = ((*(int*)&one)>>29)^1;     /* high word index */ | 
|---|
 | 37 |         *(n0+(unsigned*)&x) = | 
|---|
 | 38 |         (*(n0+(unsigned*)&x)&0x7fffffff)|(*(n0+(unsigned*)&y)&0x80000000); | 
|---|
 | 39 |         return x; | 
|---|
 | 40 | } | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.