Add prototypes for platform-independent wrappers for isinf().
[oota-llvm.git] / include / llvm / Support / MathExtras.h
1 //===-- 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 SUPPORT_MATHEXTRAS_H
15 #define SUPPORT_MATHEXTRAS_H
16
17 #include "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 bool isPowerOf2(int64_t C, unsigned &getPow) {
33   if (C < 0) C = -C;
34   if (C > 0 && C == (C & ~(C - 1))) {
35     getPow = log2(static_cast<uint64_t>(C));
36     return true;
37   }
38
39   return false;
40 }
41
42 // Platform-independent wrappers for the C99 isnan() function.
43 int IsNAN (float f);
44 int IsNAN (double d);
45
46 // Platform-independent wrappers for the C99 isinf() function.
47 int IsInf (float f);
48 int IsInf (double d);
49
50 } // End llvm namespace
51
52 #endif