compound
计算复利终值系数,入参为实数。
接口定义
C interface:
float compoundf(float x, float y);
double compound(double x, double y);
参数
参数名 |
类型 |
描述 |
输入/输出 |
|---|---|---|---|
x |
|
表示输入数据的浮点值。 |
输入 |
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
*/
父主题: 特殊函数