ilog2.c

来自「shpf 1.9一个并行编译器」· C语言 代码 · 共 39 行

C
39
字号
//======================================================================
// NPAC $Id: ilog2.C,v 1.1 1996/09/23 22:34:31 dbc Exp $
//======================================================================

int ilog2(int n) {

// _____________________________________________________________________
//|                                                                     |
//| Function to return the base-2 logarithm of an integer.              |
//|                                                                     |
//| H W Yau.  30th of January, 1994.                                    |
//| Northeast Parallel Architectures Center.                            |
//| Syracuse University.                                                |
//|_____________________________________________________________________|
//|                                                                     |
//| Edit record:                                                        |
//| 30/Jan/1995: First edit.                                            |
//| 16/Feb/1995: Removed PURE declaration of this function, PGI does    |
//|              not like it.                                           |
//| 20/Aug/1996: PGI Compiler now likes PURE attribute to function.     |
//|_____________________________________________________________________|

  int i, n2, result ;

  n2     = n ;
  result = 0 ;
  for(i = 1 ; i <= n ; i++) {
    if(n2 > 1) {
      result = result + 1 ;
      n2 = n2 / 2 ;
    }
    else {
      return result ;
    }
  }
}

//======================================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?