IxMxx有符号最值。
#include <stdio.h> #include "gotoblas2.h" #pragma comment(lib,"libgoto2.lib") //FUNCTION IxMAX (N , X, INCX) //FUNCTION IxMIN (N , X, INCX) /* ISMAX and IDMAX (Position of the First or Last Occurrence of the Vector Element Having the Maximum Value) On Entry n is the number of elements in vector x. Specified as: an integer; n greater than or equal to 0. x is the vector x of length n. Specified as: a one-dimensional array of (at least) length 1+(n-1)|incx|, containing numbers of the data type indicated in Table 1. incx is the stride for vector x. Specified as: an integer. It can have any value. On Return Function value is the position i of the element in the array, where: If incx greater than or equal to 0, i is the position of the first occurrence. If incx <= 0 or n<=0, return 0. ISMIN and IDMIN (Position of the First or Last Occurrence of the Vector Element Having Minimum Value) On Return Function value is the position i of the element in the array, where: If incx greater than 0, i is the position of the first occurrence. If incx <= 0 or n<=0, return 0. */ int main(void) { float X1[9]={1.0, 2.0, 7.0, -8.0, -5.0, -10.0, -9.0, 10.0, 6.0}; float X2[9]={1.0, .0 , 7.0, .0 , -5.0, .0, -9.0, .0 , 6.0 }; double X3[9]={1.0, 11.0, 7.0, -8.0, -5.0, -10.0, -9.0, 10.0, 6.0}; double X4[9]={1.0, .0 , 2.0, .0 , -5.0, .0, -9.0, .0 , 6.0 }; blasint IMAX,IMIN; blasint N; blasint INCX; N=9; INCX=1; IMAX=ISMAX( &N , X1 , &INCX ); printf(" The IMAX position is %d/n",(IMAX-1) * INCX + 1); IMIN=ISMIN( &N , X1 , &INCX ); printf(" The IMIN position is %d/n",(IMIN-1) * INCX + 1); N=5; INCX=2; IMAX = ISMAX( &N , X2 , &INCX ); printf(" The IMAX position is %d/n",(IMAX-1) * INCX + 1); IMIN = ISMIN( &N , X2 , &INCX ); printf(" The IMIN position is %d/n",(IMIN-1) * INCX + 1); N=9; INCX=1; IMAX=IDMAX( &N , X3 , &INCX ); printf(" The IMAX position is %d/n",(IMAX-1) * INCX + 1); IMIN=IDMIN( &N , X3 , &INCX ); printf(" The IMIN position is %d/n",(IMIN-1) * INCX + 1); N=5; INCX=2; IMAX = IDMAX( &N , X4 , &INCX ); printf(" The IMAX position is %d/n",(IMAX-1) * INCX + 1); IMIN= IDMIN( &N , X4 , &INCX ); printf(" The IMIN position is %d/n",(IMIN-1) * INCX + 1); N=9; INCX=0; IMAX = IDMAX( &N , X4 , &INCX ); IMIN = IDMIN( &N , X4 , &INCX ); if(IMAX==0&&IMIN==0) printf("/n IDMAX and IDMIN If incx <= 0 , Return 0/n"); N=0; INCX=1; IMAX = IDMAX( &N , X4 , &INCX ); IMIN = IDMIN( &N , X4 , &INCX ); if(IMAX==0&&IMIN==0) printf(" IDMAX and IDMIN If N <= 0 , Return 0/n"); return 0; } /*result The IMAX position is 8 The IMIN position is 6 The IMAX position is 3 The IMIN position is 7 The IMAX position is 2 The IMIN position is 6 The IMAX position is 9 The IMIN position is 7 IDMAX and IDMIN If incx <= 0 , Return 0 IDMAX and IDMIN If N <= 0 , Return 0 */