mirror of
https://github.com/dbalsom/x86_microcode.git
synced 2026-06-09 13:04:17 +03:00
24 lines
350 B
C++
24 lines
350 B
C++
#include "alfe/main.h"
|
|
|
|
#ifndef INCLUDED_POWER_H
|
|
#define INCLUDED_POWER_H
|
|
|
|
// Computes a^b
|
|
template<class T> T power(T a, int b)
|
|
{
|
|
T r = 1;
|
|
if (b < 0) {
|
|
a = 1/a;
|
|
b = -b;
|
|
}
|
|
while (b > 0) {
|
|
if ((b & 1) != 0)
|
|
r = r*a;
|
|
a *= a;
|
|
b >>= 1;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
#endif // INCLUDED_POWER_H
|