summaryrefslogtreecommitdiff
path: root/lib/libm/copysign.c
blob: 58be427ef7b7e2ab56752222865e1b021dd294a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <math.h>   // for copysign
#include <stdint.h> // for uint64_t

double copysign(double x, double y)
{
	union {
		double f;
		uint64_t i;
	} ux = { x }, uy = { y };
	ux.i &= -1ULL / 2;
	ux.i |= uy.i & 1ULL << 63;
	return ux.f;
}