中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助
鲲鹏小智

annuity

计算年金现值系数,输入参数为实数。

接口定义

C interface:

float annuityf(float x, float y);

double annuity(double x, double y);

参数

参数名

类型

描述

输入/输出

x

  • 在annuityf中,x是单精度浮点类型。
  • 在annuity中,x是双精度浮点类型。

表示输入数据的浮点值。

输入

y

  • 在annuityf中,y是单精度浮点类型。
  • 在annuity中,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:
    // print result
    printf("annuity(1.0, 10.0) = %.15f\n", annuity(1.0, 10.0));
    printf("annuity(0.5, -3.0) = %.15f\n", annuity(0.5, -3.0));
    printf("annuity(0.3, -10.0) = %.15f\n", annuity(1.0, 10.0));
    printf("annuity(4, 2.0) = %.15f\n", annuity(0.5, -3.0));
    printf("annuity(INFINITY, 0) = %.15f\n", annuity(INFINITY, 0));
    printf("annuity(INFINITY, 0) = %.15f\n", annuity(INFINITY, 0));
    printf("annuity(1.0, NAN) = %.15f\n", annuity(1.0, NAN));
    printf("annuity(NAN, 1.0) = %.15f\n", annuity(NAN, 1.0));
    printf("annuity(INFINITY, -1.0) = %.15f\n", annuity(INFINITY, -1.0));
    printf("annuity(INFINITY, -10.0) = %.15f\n", annuity(INFINITY, -10.0));
    printf("annuity(INFINITY, 10.0) = %.15f\n", annuity(INFINITY, 10.0));
    printf("annuity(0, 1.0) = %.15f\n", annuity(0, 1.0));
    printf("annuity(-1.0, -1.0) = %.15f\n", annuity(-1.0, -1.0));
    printf("annuity(-1.0, 1.0) = %.15f\n", annuity(-1.0, 1.0));
    printf("annuity(-10.0, 1.0) = %.15f\n", annuity(-10.0, 1.0));
    printf("annuity(-0.5, -INFINITY) = %.15f\n", annuity(-0.5, -INFINITY));
    printf("annuity(0.5, -INFINITY) = %.15f\n", annuity(0.5, -INFINITY));
    printf("annuity(-0.5, INFINITY) = %.15f\n", annuity(-0.5, INFINITY));
    printf("annuity(0.5, INFINITY) = %.15f\n", annuity(0.5, INFINITY));
    /* 
     * annuity(1.0, 10.0) = 0.999023437500000
     * annuity(0.5, -3.0) = -4.750000000000000
     * annuity(0.3, -10.0) = 0.999023437500000
     * annuity(4, 2.0) = -4.750000000000000
     * annuity(INFINITY, 0) = 0.000000000000000
     * annuity(INFINITY, 0) = 0.000000000000000
     * annuity(1.0, NAN) = nan
     * annuity(NAN, 1.0) = nan
     * annuity(INFINITY, -1.0) = -1.000000000000000
     * annuity(INFINITY, -10.0) = -inf
     * annuity(INFINITY, 10.0) = 0.000000000000000
     * annuity(0, 1.0) = 1.000000000000000
     * annuity(-1.0, -1.0) = -1.000000000000000
     * annuity(-1.0, 1.0) = inf
     * annuity(-10.0, 1.0) = nan
     * annuity(-0.5, -INFINITY) = -2.000000000000000
     * annuity(0.5, -INFINITY) = -inf
     * annuity(-0.5, INFINITY) = inf
     * annuity(0.5, INFINITY) = 2.000000000000000
     * 
     * */