idamax function

int idamax(
  1. int N,
  2. Array<double> DX_,
  3. int INCX
)

Implementation

int idamax(final int N, final Array<double> DX_, final int INCX) {
  final DX = DX_.having();

  if (N < 1 || INCX <= 0) return 0;

  if (N == 1) return 1;

  var index = 1;
  if (INCX == 1) {
    // code for increment equal to 1

    var DMAX = DX[1].abs();
    for (var I = 2; I <= N; I++) {
      if (DX[I].abs() > DMAX) {
        index = I;
        DMAX = DX[I].abs();
      }
    }
  } else {
    // code for increment not equal to 1

    var IX = 1;
    var DMAX = DX[1].abs();
    IX += INCX;
    for (var I = 2; I <= N; I++) {
      if (DX[IX].abs() > DMAX) {
        index = I;
        DMAX = DX[IX].abs();
      }
      IX += INCX;
    }
  }
  return index;
}