diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-03 10:45:50 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-03 10:45:50 +0100 |
| commit | 0d98678c1b2c3db9c6bd1860e9740c1928470c87 (patch) | |
| tree | 645df99291f72910602750cf313bf76c3dffb08a /src/zpowu.c | |
| parent | Add zabs, zadd, zdiv, zmod, zmodmul, zmodpow, zneg, zpow, zsub, and the newly introduced zmodsqr (diff) | |
| download | libzahl-0d98678c1b2c3db9c6bd1860e9740c1928470c87.tar.gz libzahl-0d98678c1b2c3db9c6bd1860e9740c1928470c87.tar.bz2 libzahl-0d98678c1b2c3db9c6bd1860e9740c1928470c87.tar.xz | |
Add new functions: zpowu and zmodpowu
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zpowu.c')
| -rw-r--r-- | src/zpowu.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/zpowu.c b/src/zpowu.c new file mode 100644 index 0000000..bc0c6dd --- /dev/null +++ b/src/zpowu.c @@ -0,0 +1,32 @@ +/* See LICENSE file for copyright and license details. */ +#include "internals" + +#include <errno.h> + +#define tb libzahl_tmp_pow_b + + +void +zpowu(z_t a, z_t b, unsigned long long int c) +{ + if (!c) { + if (zzero(b)) { + errno = EDOM; /* Indeterminate form: 0:th power of 0 */ + FAILURE_JUMP(); + } + zsetu(a, 1); + return; + } else if (zzero(b)) { + SET_SIGNUM(a, 0); + return; + } + + zset(tb, b); + zsetu(a, 1); + + for (; c; c >>= 1) { + if (c & 1) + zmul(a, a, tb); + zsqr(tb, tb); + } +} |
