39abd30929
This also "solves" the problem of GCC optimization leading to incorrect results.
43 lines
979 B
C
43 lines
979 B
C
/* @(#)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.4 1994/03/03 17:04:30 jtc 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;
|
|
}
|