2002-05-19 23:19:55 +02:00
|
|
|
//===-- Support/MathExtras.h - Useful math functions -------------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file contains some functions that are useful for math stuff.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-11-27 01:03:19 +01:00
|
|
|
|
2002-05-19 23:19:55 +02:00
|
|
|
#ifndef SUPPORT_MATH_EXTRAS_H
|
|
|
|
#define SUPPORT_MATH_EXTRAS_H
|
2001-11-27 01:03:19 +01:00
|
|
|
|
2002-10-28 03:11:53 +01:00
|
|
|
#include "Support/DataTypes.h"
|
2001-11-27 01:03:19 +01:00
|
|
|
|
2002-05-19 23:19:55 +02:00
|
|
|
inline unsigned log2(uint64_t C) {
|
2002-05-19 17:46:52 +02:00
|
|
|
unsigned getPow;
|
2002-05-19 23:19:55 +02:00
|
|
|
for (getPow = 0; C > 1; ++getPow)
|
|
|
|
C >>= 1;
|
2002-05-19 17:46:52 +02:00
|
|
|
return getPow;
|
|
|
|
}
|
2001-11-27 01:03:19 +01:00
|
|
|
|
2002-05-19 23:19:55 +02:00
|
|
|
inline bool isPowerOf2(int64_t C, unsigned &getPow) {
|
|
|
|
if (C < 0) C = -C;
|
|
|
|
if (C > 0 && C == (C & ~(C - 1))) {
|
2002-09-18 01:56:50 +02:00
|
|
|
getPow = log2((uint64_t)C);
|
2002-05-19 23:19:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2001-11-27 01:03:19 +01:00
|
|
|
}
|
|
|
|
|
2002-05-19 23:19:55 +02:00
|
|
|
#endif
|