函式
<cmath> <ctgmath>

remquo

     double remquo  (double numer     , double denom     , int* quot);      float remquof (float numer      , float denom      , int* quot);long double remquol (long double numer, long double denom, int* quot);
     double remquo (double numer     , double denom     , int* quot);      float remquo (float numer      , float denom      , int* quot);long double remquo (long double numer, long double denom, int* quot);     double remquo (Type1 numer      , Type2 denom      , int* quot);  // additional overloads
計算餘數和商
返回與 remainder 相同的值,但它還會將用於確定其結果的商內部儲存在 quot 指向的物件中。

quot 指向的值包含與整數商 numer/denom 至少3位相等的同餘模。

標頭檔案 <tgmath.h> 提供了此函式的型別通用宏版本。
此標頭檔案 (<cmath>) 中為其他算術型別 (Type1Type2) 的組合提供了額外的過載:這些過載在計算前會有效地將其引數轉換為 double,除非至少有一個引數的型別是 long double(在這種情況下,兩個引數都會被轉換為 long double)。

引數

numer
帶有商的分子部分的浮點值。
denom
帶有商的分母部分的浮點值。
quot
指向一個物件的指標,其中用於確定餘數的商作為 int 型別的值儲存。

返回值

引數相除的餘數。
如果此餘數為零,其符號應與 x 相同;在這種情況下,儲存在 quot 中的值是未指定的。
如果 denominator 為零,函式可能返回零或導致定義域錯誤(取決於庫的實現)。

如果發生定義域錯誤
- 並且 math_errhandling 設定了 MATH_ERRNO:全域性變數 errno 會被設定為 EDOM
- 並且 math_errhandling 設定了 MATH_ERREXCEPT:將引發 FE_INVALID

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* remquo example */
#include <stdio.h>      /* printf */
#include <math.h>       /* remquo */

int main ()
{
  double numer = 10.3;
  double denom = 4.5;
  int quot;
  double result = remquo (numer,denom,&quot);
  printf ("numerator: %f\n", numer);
  printf ("denominator: %f\n", denom);
  printf ("remainder: %f\n", result);
  printf ("quotient: %d\n", quot);
  return 0;
}

輸出

numerator: 10.300000
denominator: 4.500000
remainder: 1.300000
quotient: 2


另見