after multiple objections of libtom users [1], we decided to change licensing
[libtomfloat.git] / mpf_pow.c
blobdd70883e33a2700bc5df63332d0fc1e0e873d9c1
1 /* LibTomFloat, multiple-precision floating-point library
3 * LibTomFloat is a library that provides multiple-precision
4 * floating-point artihmetic as well as trigonometric functionality.
6 * This library requires the public domain LibTomMath to be installed.
7 *
8 * This library is free for all purposes without any express
9 * gurantee it works
11 * Tom St Denis, tomstdenis@iahu.ca, http://float.libtomcrypt.org
13 #include <tomfloat.h>
15 /* we have e^x, so why not write a^b as e^(lna * b) ;-) w00t w00t */
16 int mpf_pow(mp_float *a, mp_float *b, mp_float *c)
18 mp_float exponent;
19 int err;
21 if ((err = mpf_init(&exponent, c->radix)) != MP_OKAY) {
22 return err;
25 /* get ln of a */
26 if ((err = mpf_ln(a, &exponent)) != MP_OKAY) { goto __ERR; }
28 /* multiply it by b */
29 if ((err = mpf_mul(&exponent, b, &exponent)) != MP_OKAY) { goto __ERR; }
31 /* now evaluate it */
32 err = mpf_exp(&exponent, c);
34 __ERR: mpf_clear(&exponent);
35 return err;