Math Lib: pow_i for int power-of
This commit is contained in:
@@ -214,6 +214,7 @@ MINLINE int iroundf(float a);
|
|||||||
MINLINE int divide_round_i(int a, int b);
|
MINLINE int divide_round_i(int a, int b);
|
||||||
MINLINE int mod_i(int i, int n);
|
MINLINE int mod_i(int i, int n);
|
||||||
|
|
||||||
|
int pow_i(int base, int exp);
|
||||||
double double_round(double x, int ndigits);
|
double double_round(double x, int ndigits);
|
||||||
|
|
||||||
#ifdef BLI_MATH_GCC_WARN_PRAGMA
|
#ifdef BLI_MATH_GCC_WARN_PRAGMA
|
||||||
|
|||||||
@@ -31,6 +31,21 @@
|
|||||||
|
|
||||||
#include "BLI_strict_flags.h"
|
#include "BLI_strict_flags.h"
|
||||||
|
|
||||||
|
int pow_i(int base, int exp)
|
||||||
|
{
|
||||||
|
int result = 1;
|
||||||
|
BLI_assert(exp >= 0);
|
||||||
|
while (exp) {
|
||||||
|
if (exp & 1) {
|
||||||
|
result *= base;
|
||||||
|
}
|
||||||
|
exp >>= 1;
|
||||||
|
base *= base;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* from python 3.1 floatobject.c
|
/* from python 3.1 floatobject.c
|
||||||
* ndigits must be between 0 and 21 */
|
* ndigits must be between 0 and 21 */
|
||||||
double double_round(double x, int ndigits)
|
double double_round(double x, int ndigits)
|
||||||
|
|||||||
Reference in New Issue
Block a user