remainder

remainder(x1: array, x2: array, /) array

Returns the remainder of division for each element x1_i of the input array x1 and the respective element x2_i of the input array x2.

Note

This function is equivalent to the Python modulus operator x1_i % x2_i.

Note

For input arrays which promote to an integer data type, the result of division by zero is unspecified and thus implementation-defined.

Parameters:
  • x1 (array) – dividend input array. Should have a real-valued data type.

  • x2 (array) – divisor input array. Must be compatible with x1 (see Broadcasting). Should have a real-valued data type.

Returns:

out (array) – an array containing the element-wise results. Each element-wise result must have the same sign as the respective element x2_i. The returned array must have a data type determined by Type Promotion Rules.

Notes

Special cases

Note

In general, similar to Python’s % operator, this function is not recommended for floating-point operands as semantics do not follow IEEE 754. That this function is specified to accept floating-point operands is primarily for reasons of backward compatibility.

For floating-point operands,

  • If either x1_i or x2_i is NaN, the result is NaN.

  • If x1_i is either +infinity or -infinity and x2_i is either +infinity or -infinity, the result is NaN.

  • If x1_i is either +0 or -0 and x2_i is either +0 or -0, the result is NaN.

  • If x1_i is +0 and x2_i is greater than 0, the result is +0.

  • If x1_i is -0 and x2_i is greater than 0, the result is +0.

  • If x1_i is +0 and x2_i is less than 0, the result is -0.

  • If x1_i is -0 and x2_i is less than 0, the result is -0.

  • If x1_i is greater than 0 and x2_i is +0, the result is NaN.

  • If x1_i is greater than 0 and x2_i is -0, the result is NaN.

  • If x1_i is less than 0 and x2_i is +0, the result is NaN.

  • If x1_i is less than 0 and x2_i is -0, the result is NaN.

  • If x1_i is +infinity and x2_i is a positive (i.e., greater than 0) finite number, the result is NaN.

  • If x1_i is +infinity and x2_i is a negative (i.e., less than 0) finite number, the result is NaN.

  • If x1_i is -infinity and x2_i is a positive (i.e., greater than 0) finite number, the result is NaN.

  • If x1_i is -infinity and x2_i is a negative (i.e., less than 0) finite number, the result is NaN.

  • If x1_i is a positive (i.e., greater than 0) finite number and x2_i is +infinity, the result is x1_i. (note: this result matches Python behavior.)

  • If x1_i is a positive (i.e., greater than 0) finite number and x2_i is -infinity, the result is x2_i. (note: this result matches Python behavior.)

  • If x1_i is a negative (i.e., less than 0) finite number and x2_i is +infinity, the result is x2_i. (note: this results matches Python behavior.)

  • If x1_i is a negative (i.e., less than 0) finite number and x2_i is -infinity, the result is x1_i. (note: this result matches Python behavior.)

  • In the remaining cases, the result must match that of the Python % operator.