LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MathExtras.h

Go to the documentation of this file.
00001 //===-- llvm/Support/MathExtras.h - Useful math functions -------*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains some functions that are useful for math stuff.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_SUPPORT_MATHEXTRAS_H
00015 #define LLVM_SUPPORT_MATHEXTRAS_H
00016 
00017 #include "llvm/Support/DataTypes.h"
00018 
00019 namespace llvm {
00020 
00021 #if defined(log2)
00022 # undef log2
00023 #endif
00024 
00025 inline unsigned log2(uint64_t C) {
00026   unsigned getPow;
00027   for (getPow = 0; C > 1; ++getPow)
00028     C >>= 1;
00029   return getPow;
00030 }
00031 
00032 inline unsigned log2(unsigned C) {
00033   unsigned getPow;
00034   for (getPow = 0; C > 1; ++getPow)
00035     C >>= 1;
00036   return getPow;
00037 }
00038 
00039 inline bool isPowerOf2(int64_t C, unsigned &getPow) {
00040   if (C < 0) C = -C;
00041   if (C > 0 && C == (C & ~(C - 1))) {
00042     getPow = log2(static_cast<uint64_t>(C));
00043     return true;
00044   }
00045 
00046   return false;
00047 }
00048 
00049 // Platform-independent wrappers for the C99 isnan() function.
00050 int IsNAN (float f);
00051 int IsNAN (double d);
00052 
00053 // Platform-independent wrappers for the C99 isinf() function.
00054 int IsInf (float f);
00055 int IsInf (double d);
00056 
00057 } // End llvm namespace
00058 
00059 #endif