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是双精度浮点类型。

表示输入数据的浮点值。

输入

返回值

依赖

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
     */