#C 语言标准库函数 sqrtf
#include <math.h>
float sqrtf(float x);
说明
计算非负实数的主平方根。
输入小于零时发生定义域错误。
自 C99 起提供。
参数
x- 被开方数。
返回值
- 返回非负平方根。在 IEC 60559 实现中保留零的符号。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <math.h>
#include <stdio.h>
int main(void)
{
float computed = sqrtf(9.0f);
printf("%Lg\n", (long double)computed);
return !(computed == 3.0);
}
运行结果。
3
#相关接口
- 接口变体 sqrt、sqrtl、sqrtd32、sqrtd64、sqrtd128
- 类型通用分派 sqrt(类型通用宏)
- 相关操作 cbrtf、csqrtf、fsqrt、hypotf、powf、rootnf、rsqrtf