---
title: compound
description: "计算复利终值系数，入参为实数。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0602.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0602.html
indexId: fc62dca6d26630c963f889042036365eb3086ffcdc03c90a264472ae76318fdc76
---
# compound

计算复利终值系数，入参为实数。

#### 接口定义

C interface：

float compoundf(float x, float y);

double compound(double x, double y);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在compoundf中，x是单精度浮点类型。 在compound中，x是双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |
| y | 在compoundf中，y是单精度浮点类型。 在compound中，y是双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |


#### 返回值

- x大于-1且y ∈(-∞, +∞)，返回计算结果。
- 输入x为任意值，y为±0，返回0。
- 输入x为nan，y为任意值，返回nan。
- 输入x为任意值，y为nan，返回nan。
- 输入x为+∞，y为-1，则返回-1；y < -1，则返回-∞；y ∈(-1, 0)，则返回-0。
- 输入x为0，y != 0，则返回y。
- 输入x为-1，y < 0，则返回-1；y > 0，则返回+∞。
- 输入x < -1，y != 0，则返回nan。
- 输入y为-∞，x ∈(-1， 0)，则返回1.0 / x；x > 0，则返回-∞。
- 输入y为+∞，x ∈(-1， 0)，则返回+∞；x > 0，则返回1.0 / x。


#### 依赖

C: "km.h"


#### 示例

C interface：
```
printf("compound(1.0, 10.0) = %.15f\n", compound(1.0, 10.0));
printf("compound(0.5, -3.0) = %.15f\n", compound(0.5, -3.0));
printf("compound(0.3, -10.0) = %.15f\n", compound(1.0, 10.0));
printf("compound(4, 2.0) = %.15f\n", compound(0.5, -3.0));
printf("compound(INFINITY, 0) = %.15f\n", compound(INFINITY, 0));
printf("compound(INFINITY, 0) = %.15f\n", compound(INFINITY, 0));
printf("compound(1.0, NAN) = %.15f\n", compound(1.0, NAN));
printf("compound(NAN, 1.0) = %.15f\n", compound(NAN, 1.0));
printf("compound(INFINITY, -1.0) = %.15f\n", compound(INFINITY, -1.0));
printf("compound(INFINITY, -10.0) = %.15f\n", compound(INFINITY, -10.0));
printf("compound(INFINITY, 10.0) = %.15f\n", compound(INFINITY, 10.0));
printf("compound(0, 1.0) = %.15f\n", compound(0, 1.0));
printf("compound(-1.0, -1.0) = %.15f\n", compound(-1.0, -1.0));
printf("compound(-1.0, 1.0) = %.15f\n", compound(-1.0, 1.0));
printf("compound(-10.0, 1.0) = %.15f\n", compound(-10.0, 1.0));
printf("compound(-0.5, -INFINITY) = %.15f\n", compound(-0.5, -INFINITY));
printf("compound(0.5, -INFINITY) = %.15f\n", compound(0.5, -INFINITY));
printf("compound(-0.5, INFINITY) = %.15f\n", compound(-0.5, INFINITY));
printf("compound(0.5, INFINITY) = %.15f\n", compound(0.5, INFINITY));
/**
* compound(1.0, 10.0) = 1024.000000000000000
* compound(0.5, -3.0) = 0.296296296296296
* compound(0.3, -10.0) = 1024.000000000000000
* compound(4, 2.0) = 0.296296296296296
* compound(INFINITY, 0) = 1.000000000000000
* compound(INFINITY, 0) = 1.000000000000000
* compound(1.0, NAN) = nan
* compound(NAN, 1.0) = nan
* compound(INFINITY, -1.0) = 0.000000000000000
* compound(INFINITY, -10.0) = 0.000000000000000
* compound(INFINITY, 10.0) = inf
* compound(0, 1.0) = 1.000000000000000
* compound(-1.0, -1.0) = inf
* compound(-1.0, 1.0) = 0.000000000000000
* compound(-10.0, 1.0) = nan
* compound(-0.5, -INFINITY) = inf
* compound(0.5, -INFINITY) = 0.000000000000000
* compound(-0.5, INFINITY) = 0.000000000000000
* compound(0.5, INFINITY) = inf
*/
```
