Rate This Document
Findability
Accuracy
Completeness
Readability

remainder

Compute the remainder of x/y.

Interface Definition

C interface:

float remainderf(float x, float y);

double remainder(double x, double y);

long double remainderl(long double x, long double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For remainderf, x is of single-precision floating-point type.
  • For remainder, x is of double-precision floating-point type.
  • For remainderl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For remainderf, y is of single-precision floating-point type.
  • For remainder, y is of double-precision floating-point type.
  • For remainderl, y is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The result of x modulo y is returned.
  • If x is any value and y is ±0 or NaN, the return value is NaN.
  • If x is ±0 and y is not ±0 or NaN, the return value is ±0.
  • If x is ±∞ or NaN and y is any value, the return value is NaN.

Dependency

C: "km.h"

Example

C interface:

    // typical usage
    float x1 = 3.0, x2 = 3.5;
    float y1 = 4.0, y2 = 4.5;
    // special handling
    float e = INFINITY, f = -INFINITY, g = NAN;
    // print result
    printf("remainder(3.0, 4.0) = %.15f\n", remainder(x1, y1));
    printf("remainder(3.5, 4.5) = %.15f\n", remainder(x2, x2));
    printf("remainder(4.5, 4.5) = %.15f\n", remainder(y2, y2));
    printf("remainder(INFINITY, 0) = %.15f\n", remainder(e, 0.0f));
    printf("remainder(-INFINITY, 3.0) = %.15f\n", remainder(f, x1));
    printf("remainder(NAN, 3.0) = %.15f\n", remainder(g, x1));
    printf("remainder(NAN, INFINITY) = %.15f\n", remainder(g, e));

    /* 
     *  remainder(3.0, 4.0) = -1.000000000000000
     *  remainder(3.5, 4.5) = 0.000000000000000
     *  remainder(4.5, 4.5) = 0.000000000000000
     *  remainder(INFINITY, 0) = nan
     *  remainder(-INFINITY, 3.0) = nan
     *  remainder(NAN, 3.0) = nan
     *  remainder(NAN, INFINITY) = nan
     * */