diff options
author | Tyler Murphy <=> | 2023-07-16 02:54:32 -0400 |
---|---|---|
committer | Tyler Murphy <=> | 2023-07-16 02:54:32 -0400 |
commit | fbf131b5c043b27e0b1543374bb144e3e426f723 (patch) | |
tree | 07f0ab2fc107b36621d5ae95480e6a91e332548b /libk/src/math/copysign.c | |
download | finix-fbf131b5c043b27e0b1543374bb144e3e426f723.tar.gz finix-fbf131b5c043b27e0b1543374bb144e3e426f723.tar.bz2 finix-fbf131b5c043b27e0b1543374bb144e3e426f723.zip |
initial
Diffstat (limited to 'libk/src/math/copysign.c')
-rw-r--r-- | libk/src/math/copysign.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libk/src/math/copysign.c b/libk/src/math/copysign.c new file mode 100644 index 0000000..fd5fd4f --- /dev/null +++ b/libk/src/math/copysign.c @@ -0,0 +1,20 @@ +#include <math.h> +#include <stdint.h> + +#define DMASK 0x8000000000000000 + +double copysign(double n, double s) { + union {double f; uint64_t i;} sb = {s}; + union {double f; uint64_t i;} nb = {n}; + nb.i = (nb.i & ~DMASK) | (sb.i & DMASK); + return nb.f; +} + +#define FMASK 0x80000000 + +float copysignf(float n, float s) { + union {float f; uint32_t i;} sb = {s}; + union {float f; uint32_t i;} nb = {n}; + nb.i = (nb.i & ~FMASK) | (sb.i & FMASK); + return nb.f; +} |