divのヘルプ・マニュアル
日本語 英語
div --help
man div
DIV(3) Linux Programmer’s Manual DIV(3)
名前
div, ldiv, lldiv, imaxdiv - integer 型の割算の商と余りを計算する
書式
#include
div_t div(int numerator, int denominator);
ldiv_t ldiv(long numerator, long denominator);
lldiv_t lldiv(long long numerator, long long denominator);
#include
imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
lldiv(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99
説明
div() 関数は numerator/denominator の値を計算する。商と余りは、 quot (
商) と rem (余り) という名前の 2 つの integer 型メンバを含む div_t とい
う 構造体の中に返される (メンバの順番は不定である)。商は 0 に近い方に丸
められる。結果は quot*denominator+rem = numerator を満たす。
ldiv(), lldiv(), imaxdiv() 関数は同様な動作をし、上に示した型の数値を割
算して、上に示した名前の構造体に結果を返す。どの場合でもフィールド quot
と rem は、関数の引き数と同じ型である。
返り値
div_t (などの) 構造体。
準拠
SVr4, 4.3BSD, C89. 関数 lldiv() と imaxdiv() は C99 に追加された。
例
div_t q = div(-5, 3);
を計算すると、q.quot と q.rem はそれぞれ -1 と -2 になる。
関連項目
abs(3), remainder(3)
2007-07-26 DIV(3)
DIV(3) Linux Programmer’s Manual DIV(3)
NAME
div, ldiv, lldiv, imaxdiv - compute quotient and remainder of an inte-
ger division
SYNOPSIS
#include
div_t div(int numerator, int denominator);
ldiv_t ldiv(long numerator, long denominator);
lldiv_t lldiv(long long numerator, long long denominator);
#include
imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
lldiv(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99
DESCRIPTION
The div() function computes the value numerator/denominator and returns
the quotient and remainder in a structure named div_t that contains two
integer members (in unspecified order) named quot and rem. The quo-
tient is rounded towards zero. The result satisfies quot*denomina-
tor+rem = numerator.
The ldiv(), lldiv(), and imaxdiv() functions do the same, dividing num-
bers of the indicated type and returning the result in a structure of
the indicated name, in all cases with fields quot and rem of the same
type as the function arguments.
RETURN VALUE
The div_t (etc.) structure.
CONFORMING TO
SVr4, 4.3BSD, C89. The functions lldiv() and imaxdiv() were added in
C99.
EXAMPLE
After
div_t q = div(-5, 3);
the values q.quot and q.rem are -1 and -2, respectively.
SEE ALSO
abs(3), remainder(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2007-07-26 DIV(3)