⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intexp.c

📁 LVQ - Learning Vector Quantization Demonstration Download xlvq Linux executable (128 kb) wlvq.ex
💻 C
字号:
/*----------------------------------------------------------------------  File    : intexp.c  Contents: raise x to the power of n, n integer  Author  : Christian Borgelt  History : 17.05.2003 file created----------------------------------------------------------------------*/#include "intexp.h"/*----------------------------------------------------------------------  Functions----------------------------------------------------------------------*/#if 0double intexp (double x, int n){                               /* --- raise x to the power of n */  if (n <= 0) return 0;         /* check for immediate cases, otherw. */  if (n <= 1) return x;         /* apply the recursive formula */  if (n &  1) return intexp(x*x, n >> 1) *x;  else        return intexp(x*x, n >> 1);}  /* intexp() */#else /*--------------------------------------------------------------*/double intexp (double x, int n){                               /* --- raise x to the power of n */  double r = (n & 1) ? x : 1;   /* result */  for (n >>= 1; n > 0; n >>= 1) {    x *= x;                     /* traverse the powers of 2 and */    if (n & 1) r *= x;          /* multiply them into the result */  }                             /* if the corr. exponent bit is set */  return r;                     /* return the result */}  /* intexp() */#endif

⌨️ 快捷键说明

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