summaryrefslogtreecommitdiff
path: root/libk/src/math/abs.c
diff options
context:
space:
mode:
Diffstat (limited to 'libk/src/math/abs.c')
-rw-r--r--libk/src/math/abs.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libk/src/math/abs.c b/libk/src/math/abs.c
new file mode 100644
index 0000000..1757272
--- /dev/null
+++ b/libk/src/math/abs.c
@@ -0,0 +1,14 @@
+#include <math.h>
+#include <stdint.h>
+
+float fabsf(float num) {
+ union {float f; uint32_t i;} u = {num};
+ u.i &= 0x7fffffff;
+ return u.f;
+}
+
+double fabs(double num) {
+ union {double f; uint64_t i;} u = {num};
+ u.i &= -1ULL/2;
+ return u.f;
+}