diff options
Diffstat (limited to 'zap/source/any/mth/divmod.c')
-rw-r--r-- | zap/source/any/mth/divmod.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/zap/source/any/mth/divmod.c b/zap/source/any/mth/divmod.c new file mode 100644 index 0000000..4214651 --- /dev/null +++ b/zap/source/any/mth/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) |