cc [ flag ... ] file ... -lsunmath -lm [ library ... ]
#include <sunmath.h>
double annuity(double r, double n);
float annuityf(float r, float n);
long double annuityl(long double r, long double n);
double compound(double r, double n);
float compoundf(float r, float n);
long double compoundl(long double r, long double n);
这些函数适用于以定期利率 r 计算 n 个期间的利息收益。
annuity(r, n) 计算年金系数的现值 (1 - (1+r)**-n)/r。compound(r, n) 计算复利系数 (1+r)**n。当 r <= -1 时,这两个函数都返回 NaN。对于合理的 r 值和 n 值,会对这些函数谨慎求值,以便获得准确的结果,避免伪浮点异常。在这方面,它们优于使用 pow(3m) 函数的对应表达式的文字求值。
在以定期利率 r 计算的 n 个期间的收益之后的初始本金 P0 值为 P = P0 * compound(r, n)。因此,本金金额 P0 每季度结算的以 5% 年复合利率获得 30 年收益为
P = P0 * compound(.05 / 4, 30.0 * 4)
如果初始本金为 P0,则等效的定期支付为 p = P0/annuity(r, n)。因此,常规固定利率 30 年家庭贷款金额 P0 以 10% 年利率计算每月分期偿还的金额为
p = P0 / annuity(.10 / 12, 30.0 * 12)
有关下列属性的说明,请参见 attributes(5):
|
pow(3M)、attributes(5)