在C语言中,可以使用math.h库中提供的函数来进行高级浮点数运算。以下是一些常用的函数示例:
pow()函数来计算一个数的指数,如pow(x, y)表示计算x的y次方。#include <stdio.h>#include <math.h>int main() { double result = pow(2, 3); // 计算2的3次方 printf("2^3 = %f\n", result); return 0;}开方运算:使用sqrt()函数来计算一个数的平方根。#include <stdio.h>#include <math.h>int main() { double result = sqrt(16); // 计算16的平方根 printf("sqrt(16) = %f\n", result); return 0;}对数运算:使用log()函数来计算一个数的自然对数,log10()函数来计算一个数的10为底的对数。#include <stdio.h>#include <math.h>int main() { double result = log(2.71828); // 计算自然对数 printf("ln(e) = %f\n", result); double result2 = log10(100); // 计算以10为底的对数 printf("log10(100) = %f\n", result2); return 0;}三角函数运算:sin(), cos(), tan()分别用来计算正弦、余弦、正切值。#include <stdio.h>#include <math.h>int main() { double result = sin(1.5708); // 计算sin(π/2) printf("sin(π/2) = %f\n", result); double result2 = cos(0); // 计算cos(0) printf("cos(0) = %f\n", result2); double result3 = tan(0.7854); // 计算tan(π/4) printf("tan(π/4) = %f\n", result3); return 0;}这些仅仅是math.h库中提供的一些常用函数,还有更多的数学函数可以用来进行高级浮点数运算。




