summaryrefslogtreecommitdiff
path: root/zap/source/any/math
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/any/math')
-rw-r--r--zap/source/any/math/abs.c20
-rw-r--r--zap/source/any/math/div0.c22
-rw-r--r--zap/source/any/math/divmod.c24
-rw-r--r--zap/source/any/math/exp.c24
4 files changed, 90 insertions, 0 deletions
diff --git a/zap/source/any/math/abs.c b/zap/source/any/math/abs.c
new file mode 100644
index 0000000..d12b6a6
--- /dev/null
+++ b/zap/source/any/math/abs.c
@@ -0,0 +1,20 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <zap/math.h>
+
+#define zap_priv_abs(_wdth) \
+zap_i##_wdth zap_abs##_wdth(zap_i##_wdth##s const _val) { \
+ if (_val > 0x0) { \
+ return (zap_i##_wdth)_val; \
+ } \
+ return (zap_i##_wdth)(0x0 - _val); \
+}
+
+zap_priv_abs(8)
+zap_priv_abs(01)
+zap_priv_abs(02)
+zap_priv_abs(04)
diff --git a/zap/source/any/math/div0.c b/zap/source/any/math/div0.c
new file mode 100644
index 0000000..87fcfa0
--- /dev/null
+++ b/zap/source/any/math/div0.c
@@ -0,0 +1,22 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <zap/math.h>
+
+#include <csys.h>
+
+#if csys_os_linux
+#include <asm/unistd.h>
+#endif
+
+zap_i04 zap_priv_div0(void) {
+#if defined(zap_priv_signaldiv0)
+#if csys_os_linux
+ csys_syscall(__NR_kill,csys_syscall(__NR_getpid),0x8u);
+#endif
+#endif
+ return (zap_i04)-0x1;
+}
diff --git a/zap/source/any/math/divmod.c b/zap/source/any/math/divmod.c
new file mode 100644
index 0000000..4214651
--- /dev/null
+++ b/zap/source/any/math/divmod.c
@@ -0,0 +1,24 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <zap/math.h>
+
+#define zap_priv_divmod(_wdth) \
+zap_quotrem##_wdth zap_divmod##_wdth(zap_i##_wdth const _num,zap_i##_wdth const _den) { \
+zap_quotrem##_wdth quotrem; \
+ if (__builtin_expect(_den == 0x0,0x0)) { \
+ quotrem.quot = zap_priv_div0(); \
+ quotrem.rem = quotrem.quot; \
+ return quotrem; \
+ } \
+ for (quotrem = (zap_quotrem##_wdth){.quot = 0x0u,.rem = _num};quotrem.rem >= _den;++quotrem.quot,quotrem.rem -= _den) {} \
+ return quotrem; \
+}
+
+zap_priv_divmod(8)
+zap_priv_divmod(01)
+zap_priv_divmod(02)
+zap_priv_divmod(04)
diff --git a/zap/source/any/math/exp.c b/zap/source/any/math/exp.c
new file mode 100644
index 0000000..6c16213
--- /dev/null
+++ b/zap/source/any/math/exp.c
@@ -0,0 +1,24 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <zap/math.h>
+
+#define zap_priv_exp(_wdth) \
+zap_i##_wdth zap_exp##_wdth(zap_i##_wdth const _val,zap_i##_wdth const _n) { \
+ if (_val == 0x0) { \
+ return 0x1u; \
+ } \
+ zap_i##_wdth val = _val; \
+ for (zap_i##_wdth i = 0x1u;i < _n;++i) { \
+ val *= _val; \
+ } \
+ return val; \
+}
+
+zap_priv_exp(8)
+zap_priv_exp(01)
+zap_priv_exp(02)
+zap_priv_exp(04)