sasum.c
来自「InsightToolkit-1.4.0(有大量的优化算法程序)」· C语言 代码 · 共 42 行
C
42 行
#include "f2c.h"
#include "netlib.h"
real sasum_(n, sx, incx)
const integer *n;
const real *sx;
const integer *incx;
{
/* Local variables */
static integer i, m, nincx;
static real stemp;
/* takes the sum of the absolute values. */
/* uses unrolled loops for increment equal to one. */
/* jack dongarra, linpack, 3/11/78. */
/* modified 3/93 to return if incx .le. 0. */
/* modified 12/3/93, array(1) declarations changed to array(*) */
stemp = 0.f;
if (*n <= 0 || *incx <= 0) {
return stemp;
}
/* code for increment equal to 1 */
if (*incx == 1) {
m = *n % 6;
for (i = 0; i < m; ++i) {
stemp += abs(sx[i]);
}
for (i = m; i < *n; i += 6) {
stemp += abs(sx[i]) + abs(sx[i+1]) + abs(sx[i+2]) + abs(sx[i+3]) + abs(sx[i+4]) + abs(sx[i+5]);
}
}
/* code for increment not equal to 1 */
else {
nincx = *n * *incx;
for (i = 0; i < nincx; i += *incx) {
stemp += abs(sx[i]);
}
}
return stemp;
} /* sasum_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?