我要评分
获取效率
正确性
完整性
易理解

fmod

Compute the modulus of x with respect to y, that is x modulo y. x and y are of the floating-point type.

Interface Definition

C interface:

float fmodf(float x, float y);

double fmod(double x, double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For fmodf, x is of single-precision floating-point type.

Floating-point value of the input data

Input

y

  • For fmodf, y is of single-precision floating-point type.

Floating-point value of the input data

Input

x

  • For fmod, x is of double-precision floating-point type.

Floating-point value of the input data

Input

y

  • For fmod, y is of double-precision floating-point type.

Floating-point value of the input data

Input

Return Value

Return the result of x modulo y.

  • 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.

Dependencies

C: "km.h"

Examples

C interface:

    // typical usage 
    float x1 = -1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0;
    float y1 = 4.0, y2 = -4.0, y3 = -3.0, y4 = 3.0;
    // special handing 
    float a = 0.0, b = INFINITY, c = -INFINITY, d = NAN; 
    // print result 
    printf("fmodf(-1.0, 4.0) = %.6f\n", fmodf(x1, y1));
    printf("fmodf(2.0, -4.0) = %.6f\n", fmodf(x2, y2));
    printf("fmodf(3.0, -3.0) = %.6f\n", fmodf(x3, y3));
    printf("fmodf(4.0, 3.0) = %.6f\n", fmodf(x4, y4));
    printf("fmodf(1.0, 0.0) = %+.6f\n", fmodf(x1, a));
    printf("fmodf(INFINITY, 1.0) = %+.6f\n", fmodf(b, x1));
    printf("fmodf(-INFINITY, -1.0) = %+.6f\n", fmodf(c, -x1));
    printf("fmodf(1.0, -INFINITY) = %+.6f\n", fmodf(x1, c));
    printf("fmodf(1.0, NAN) = %+.6f\n", fmodf(x1, d));
    printf("fmodf(NAN, -1.0) = %+.6f\n", fmodf(d, -x1));

    /* 
     *  fmodf(-1.0, 4.0) = -1.000000
     *  fmodf(2.0, -4.0) = 2.000000
     *  fmodf(3.0, -3.0) = 0.000000
     *  fmodf(4.0, 3.0) = 1.000000
     *  fmodf(1.0, 0.0) = -nan
     *  fmodf(INFINITY, 1.0) = -nan
     *  fmodf(-INFINITY, -1.0) = -nan
     *  fmodf(1.0, -INFINITY) = +1.000000
     *  fmodf(1.0, NAN) = +nan
     *  fmodf(NAN, -1.0) = +nan
     * */