Changes For Bug 352
[oota-llvm.git] / include / llvm / Support / MathExtras.h
1 //===-- llvm/Support/MathExtras.h - Useful math functions -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains some functions that are useful for math stuff.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_MATHEXTRAS_H
15 #define LLVM_SUPPORT_MATHEXTRAS_H
16
17 #include "llvm/Support/DataTypes.h"
18
19 namespace llvm {
20
21 #if defined(log2)
22 # undef log2
23 #endif
24
25 inline unsigned log2(uint64_t C) {
26   unsigned getPow;
27   for (getPow = 0; C > 1; ++getPow)
28     C >>= 1;
29   return getPow;
30 }
31
32 inline unsigned log2(unsigned C) {
33   unsigned getPow;
34   for (getPow = 0; C > 1; ++getPow)
35     C >>= 1;
36   return getPow;
37 }
38
39 inline bool isPowerOf2(int64_t C, unsigned &getPow) {
40   if (C < 0) C = -C;
41   if (C > 0 && C == (C & ~(C - 1))) {
42     getPow = log2(static_cast<uint64_t>(C));
43     return true;
44   }
45
46   return false;
47 }
48
49 // Platform-independent wrappers for the C99 isnan() function.
50 int IsNAN (float f);
51 int IsNAN (double d);
52
53 // Platform-independent wrappers for the C99 isinf() function.
54 int IsInf (float f);
55 int IsInf (double d);
56
57 } // End llvm namespace
58
59 #endif