다음을 통해 공유


operator%

Obtains the remainder of dividing the corresponding elements of two equally sized valarrays or of dividing a valarray by a specified value or of dividing a specified value by a valarray.

template<class Type>
   valarray<Type> operator%(
      const valarray<Type>& _Left,
      const valarray<Type>& _Right
   );
template<class Type>
   valarray<Type> operator%(
      const valarray<Type>& _Left,
      const Type& _Right
   );
template<class Type>
   valarray<Type> operator%(
      const Type& _Left,
      const valarray<Type>& _Right
   );

Parameters

  • _Left
    A value or valarray that serves as the dividend into which another value or valarray is to be divided.

  • _Right
    A value or valarray that serves as the divisor and that divides another value or valarray.

Return Value

A valarray whose elements are the element-wise remainders of _Left divided by _Right.

Example

// valarray_op_rem.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>

int main( )
{
   using namespace std;
   int i;

   valarray<int> vaL ( 6 ), vaR ( 6 );
   valarray<int> vaREM ( 6 );
   for ( i = 0 ; i < 6 ; i += 2 )
      vaL [ i ] =  53;
   for ( i = 1 ; i < 6 ; i += 2 )
      vaL [ i ] =  -67;
   for ( i = 0 ; i < 6 ; i++ )
      vaR [ i ] =  3*i+1;
   
   cout << "The initial Left valarray is: ( ";
      for ( i = 0 ; i < 6 ; i++ )
         cout << vaL [ i ] << " ";
   cout << ")." << endl;

   cout << "The initial Right valarray is: ( ";
      for ( i = 0 ; i < 6 ; i++ )
         cout << vaR [ i ] << " ";
   cout << ")." << endl;

   vaREM = ( vaL % vaR );
   cout << "The remainders from the element-by-element "
        << "division is the\n valarray: ( ";
      for ( i = 0 ; i < 6 ; i++ )
         cout << vaREM [ i ] << " ";
   cout << ")." << endl;
}

The initial Left valarray is: ( 53 -67 53 -67 53 -67 ).
The initial Right valarray is: ( 1 4 7 10 13 16 ).
The remainders from the element-by-element division is the
 valarray: ( 0 -3 4 -7 1 -3 ).

Requirements

Header: <valarray>

Namespace: std

See Also

Concepts

<valarray> Members