fmodを使用するとdouble同士の割り算の余りを求めることができます。
以下にCサンプルコードと実行例を記します。
float型向けのfmodf, long double型向けのfmodlもあります。
以下にfmodの書式等を記します。
#include <math.h>
double fmod(double x, double y);
以下にfmodのCサンプルコードと実行例を記します。
&ref(): File not found: "fmod.c" at page "数値/割り算の余りをdobule型で返す・fmod"; (改行コードLF)
#include <stdio.h> #include <math.h> int main(void) { double a, b; a = 123.123; b = 12.12; printf("fmod(%f, %f) = %f\n", a, b, fmod(a, b)); return 0; }
以下にコンパイルと実行結果を記します。
コンパイル時に-lmオプションが必要になります。
$ gcc fmod.c -lm -o fmod $ ./fmod fmod(123.123000, 12.120000) = 1.923000
以上、double型の割り算の余りを求めるfmodの紹介でした。