【c】math库函数
绝对值
#include <math.h>
int main() {
printf("%lf\n", fabs(-4.2));
return 0;
}
取整
#include <math.h>
int main() {
printf("%lf\n", ceil(2.6));
return 0;
}
int main() {
printf("%lf\n", floor(2.7));
return 0;
}
```c
## 取模
```c
#include <math.h>
int main() {
printf("%lf\n", fmod(15, 4.3));
return 0;
}
次幂
#include <math.h>
int main() {
printf("%lf\n", pow(2, 3));
return 0;
}
int main() {
printf("%lf\n",sqrt(9));
return 0;
}
对数
#include <math.h>
int main() {
printf("%lf\n", log2(16));
return 0;
}
三角函数
sinx
#include <math.h>
int main() {
printf("%lf\n", sin(3.1415926536 / 6));
return 0;
}
cosx
int main() {
printf("%lf\n", cos(3.1415926536 / 3));
return 0;
}
tanx
int main() {
printf("%lf\n", tan(3.1415926536 / 4));
return 0;
}
cotx math.h中没有cot函数
int main() {
printf("%lf\n", 1/tan(3.1415926536 / 4));
return 0;
}
反三角函数
arcsinx
#include <math.h>
int main() {
printf("%lf\n", asin(sin(1)));
return 0;
}
arccosx
int main() {
printf("%lf\n", acos(cos(2)));
return 0;
}
arctanx
int main() {
printf("%lf\n", atan(tan(3)));
return 0;
}
双曲函数
#include <math.h>
int main() {
printf("%lf\n", tanh(0));
return 0;
}