当前位置: C语言 -- 标准库 -- <math.h> -- compoundn

compoundn函数


概要:
#include <math.h>
double compoundn(double x,long long int n);

描述:

该函数计算(1+x)n的值。

如果x<-1,会发生域错误。取决于n的值,如果正有限的x值太大,或者x非常接近但不等于-1时,会发生范围错误。如果x=-1,并且n<0,可能发生极点错误。


参数:
double x

参数为double类型的浮点数。

long long int n

参数为long long int类型的整数。


返回值:

函数返回(1+x)n。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
/*函数compoundn范例*/

#include <math.h>
#include <stdio.h>

int main(void)
{
    #if __STDC_VERSION_MATH_H__ >= 202311L
        double x = 5.0,y;
        long long int n = 2LL;

        y = compoundn(x,n);
        printf("compoundn(%.6f,%lld) = %.6f\n", x,n,y);
    #else
        puts("The implementation does not support compoundn function.");
    #endif

    return 0;
}

输出:

The implementation does not support compoundn function.


相关内容:
compoundnf float类型的返回(1+x)n的函数。
compoundnl long double类型的返回(1+x)n的函数。
compoundnd32 _Decimal32类型的返回(1+x)n的函数。
compoundnd64 _Decimal64类型的返回(1+x)n的函数。
compoundnd128 _Decimal128类型的返回(1+x)n的函数。


主要参考资料:

1、ISO/IEC 9899:2024