The problem with converting Fortran90 to C #

I am converting Fortran90 code in C #. I have some knowledge of Fortran77, but I am not familiar with Fortran90. I missed the next line of code, which I'm not sure how to translate.

C1 = real(product((/(-1,i1=1,m-1)/))*product((/(i1,i1=2,m)/)))

I think this should be converted as:

int product1 = -1; int product2 = 1;
for (int i1 = 1 ; i1 <= (m-1); i1++)
{
    product1 *= -1;
}
for (int i2 = 2, i2 <= m; i2++)
{
    product2 *= i2;
}
float C1 = (float)(product1 * product2);

My uncertainty is that there is an implied do loop construct to initialize arrays; i.e.

A = (/2*I, I = 1,5/)

but I have never seen the word “product” used as in the Fortran statement in question. I know that there is an internal function for vector or matrix multiplication called PRODUCT, but the “product” is not an array in the code I'm working with and the syntax of the intrisic function. PRODUCT uses MASK so that my operator does not use this function.

. .

+5
1

, , , :

! given: (/(expr, start, end)/)
!
! (/(-1, i1=1, m-1)/) = vector, -1 repeated m-1 times
!
! (/(i1, i1=2, m)/)   = vector, 2..m
!
! Both are vectors with m-1 terms

, product() 3 . ( ) ( ) .

, -1 m-1 m!.

, ( ) :

// product((/(-1,i1=1,m-1)/)) => -1^m-1
double i = (m % 2 == 0 ? -1 : 1);

// product((/(i1,i1=2,m)/))   => m!
double mfact = i;
for (int jj = 2; jj < m; ++jj)
{
    mfact *= jj;
} // C1 = mfact;

, "" F90, :

double i = (m % 2 == 0 ? -1 : 1);
double C1 = Enumerable.Range(2, m)
                      .Aggregate(i, (x, y) => x * y);
+7

All Articles