1 2 3 4 5 6 7 8 9 10 11 12 13
#include <math.h> // for copysignf #include <stdint.h> // for uint32_t float copysignf(float x, float y) { union { float f; uint32_t i; } ux = { x }, uy = { y }; ux.i &= 0x7fffffff; ux.i |= uy.i & 0x80000000; return ux.f; }