The remainder functions (C99) - remainder, remainderf, remainderl

IEEE 60559 が要求する余剰 x REM y を計算します.

remainder (C99)

#include <math.h>
double remainder(
    double x,
    double y
);

remainder 関数は IEEE 60559 が要求する余剰 x REM y を計算し,結果を double 型で返します.

remainderf (C99)

#include <math.h>
float remainderf(
    float x,
    float y
);

remainderf 関数は IEEE 60559 が要求する余剰 x REM y を計算し,結果を float 型で返します.

remainderl (C99)

#include <math.h>
long double remainderl(
    long double x,
    long double y
);

remainderl 関数は IEEE 60559 が要求する余剰 x REM y を計算し,結果を long double 型で返します.

戻り値

  • x REM y の値

C言語サンプルプログラム

以下に remainder 関数を使用したサンプルプログラムを示します.

/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* main */
int main(void) {
    double x, y;
    double rem;

    printf("x の値を入力して下さい> ");
    scanf("%lf", &x);

    printf("y の値を入力して下さい> ");
    scanf("%lf", &y);

    /* 余剰を求める */
    rem = remainder(x, y);

    printf("%.2f %% %.2f = %.2f\n", x, y, rem);

    return EXIT_SUCCESS;
}

実行例

サンプルプログラムの実行結果は以下のようになります.

x の値を入力して下さい> 9
y の値を入力して下さい> 2
9.00 REM 2.00 = 1.00

x の値を入力して下さい> -9
y の値を入力して下さい> 2
-9.00 REM 2.00 = -1.00

x の値を入力して下さい> 9
y の値を入力して下さい> -2
9.00 REM -2.00 = 1.00

x の値を入力して下さい> 9.5
y の値を入力して下さい> 2
9.50 REM 2.00 = -0.50

x の値を入力して下さい> -9.5
y の値を入力して下さい> 2
-9.50 REM 2.00 = 0.50